For Loop Array of Javascript Objects

var dog1 = {name:”frank”, breed:”mix”};

var dog2 = {name:”abby”, breed:”mix”};

var dogArray = [];

dogArray.push(dog1);

dogArray.push(dog2);

I have found some JavaScript engines are OK with this:

for(var x = 0; x < dogArray.length; x++){

But many are not, and it needs to be declared as:

for(var x = 0; x < Object.keys(dogArray).length; x++){

Advertisements