Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

random image generator javascript using objects

//Data
let memesData= {
    "success": true,
    "data": {
        "memes": [
            {
                "id": "181913649",
                "name": "Drake Hotline Bling",
                "url": "https://i.imgflip.com/30b1gx.jpg",
                "width": 1200,
                "height": 1200,
                "box_count": 2
            },
            {
                "id": "87743020",
                "name": "Two Buttons",
                "url": "https://i.imgflip.com/1g8my4.jpg",
                "width": 600,
                "height": 908,
                "box_count": 3
            },
            {
                "id": "112126428",
                "name": "Distracted Boyfriend",
                "url": "https://i.imgflip.com/1ur9b0.jpg",
                "width": 1200,
                "height": 800,
                "box_count": 3
            },
            {
                "id": "131087935",
                "name": "Running Away Balloon",
                "url": "https://i.imgflip.com/261o3j.jpg",
                "width": 761,
                "height": 1024,
                "box_count": 5
            },
            {
                "id": "247375501",
                "name": "Buff Doge vs. Cheems",
                "url": "https://i.imgflip.com/43a45p.png",
                "width": 937,
                "height": 720,
                "box_count": 4
            },
            {
                "id": "129242436",
                "name": "Change My Mind",
                "url": "https://i.imgflip.com/24y43o.jpg",
                "width": 482,
                "height": 361,
                "box_count": 2
            },
            {
                "id": "124822590",
                "name": "Left Exit 12 Off Ramp",
                "url": "https://i.imgflip.com/22bdq6.jpg",
                "width": 804,
                "height": 767,
                "box_count": 3
            }
        ]
    }
}
//Extracting images only from the data in an array
let varr=[]
let memeimg = memesData.data.memes.map(x =>{
     varr.push(x.url)
})
// Using some math.random function and we are good to go
let randomImgGenerator=(params)=>{
      return params[Math.floor(Math.random()*params.length)]        
}
console.log(randomImgGenerator(varr))
 
PREVIOUS NEXT
Tagged: #random #image #generator #javascript #objects
ADD COMMENT
Topic
Name
7+8 =