Skip to content Skip to sidebar Skip to footer

Getting Value Of Multi Array In Js?

How can I get the values of id in this array within a for loop? var image_array = [ {image: 'images/candidates/1.jpg', link_url: 'images/candidates/1.jpg', link_rel: 'prettyPho

Solution 1:

You can use this:

for (i = 0; i<image_array.length;i++){
    console.log(image_array[i].id);
}

If you want one specific you can use for example image_array[2].id which gives you 2

Demo here

(look at console)

Solution 2:

If you've got jquery to work with, this beauty will give you an array of the ids.

var image_array_by_id = $.map(image_array, function (index) { return index.id });

Post a Comment for "Getting Value Of Multi Array In Js?"