I want to loop through an array of objects, and for each object console.log its attributes. Let’s say we don’t know what the attributes are.
The code looks like this.
qData = [object ,object, object, object, object];
for(props in qData){
//display all of props object attributes
}
How can I output their attributes?
You can do that like this:
You first iterate through the array and then for each array element, you iterate through the properties. Keep in mind that you iterate array elements with
for (var i = 0; i < array.length; i++)and you iterate properties withfor (props in array).If you only want direct properties of the object (and not any enumerable properties of parent objects), you would use this: