Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

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];
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.