Javascript – How to get an index of random property of array of objects?
I have an array of objects. const items = [{ name: "item1", img: "img/pic/picture1.png" }, name: "item2", img: "img/pic/picture2.png" }, name: "item3", img: "img/pic/picture3.png" }]; I'm getting a random img property from it. const randomImg =items[Math.floor(Math.random() *items.length)].img; itemImg.src = `${randomImg}`;…