简体   繁体   中英

loop through nested objects with javascript

i' got this code and want to show all images with the foreach() function.

var btx = [];
btx["main"] = {};
btx["main"]["us-001"] = {src: "hxxps://domain.com/kus-001.jpg", width: "128" , height: "256"};
btx["main"]["us-002"] = {src: "hxxps://domain.com/kus-002.jpg", width: "128" , height: "256"};

thanks

for (var key in btx["main"]) {
    console.log (btx["main"][key]["src"])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM