javascript - Get all string values from a nested object -



javascript - Get all string values from a nested object -

i have object, nested objects. how target specific index of object , loop through nested values of image. note length of nested objects vary.

target example: productarray[0].image = test1.png, test2.png, test3.png

var products = [ //item1 { identifier: "item-0", image: { "img1": "test1.png", "img2": "test2.png", "img3": "test3.png" } }, //item2 { identifier: "item-1", image: { "img1": "test1.png", "img2": "test2.png" } }, //item3 { identifier: "item-2", image: { "img1": "test1.png", "img2": "test2.png", "img3": "test3.png", "img4": "test4.png", "img5": "test5.png", "img6": "test6.png", "img7": "test7.png" } } ];

we can this. need simple loop through object @ specific index, or can target them all. note image object not array, not have accurate length property.

target indexes:

for(var = 0; < products.length; i++) { console.log("item: " + i); var images = products[i].image; for(var in images) console.log(images[a]); }

target specific:

for(var in products[0].image) console.log(products[0].image[i]);

i used loop here, can utilize while loop if like.

example

javascript arrays object

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -