I am trying to get objects from an array. For example;
var array = [{foo:'bar', baz: 'quz'}];
I can access the objects as follows
array[0].foo
// Which would return 'bar'
But I want to be able to loop through and print all the objects. Is there anyway to do so? Is there anything similar to a wildcard like '*' to grab everything?
asked Sep 18, 2013 at 9:11
Collin McGuire
7243 gold badges8 silver badges14 bronze badges
1 Answer 1
Just loop your array:
for ( var i = 0; i < array.length; i++ ) {
for ( var key in array[i] ) {
var value = array[i][key];
}
}
answered Sep 18, 2013 at 9:14
hsz
153k63 gold badges269 silver badges320 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js