javascript - How to loop through an array containing objects and access their properties -


i want cycle through objects contained in array , change properties of each one. if this:

for (var j = 0; j < myarray.length; j++){  console.log(myarray[j]);  } 

the console should bring every object in array, right? in fact displays first object. if console log array outside of loop, objects appear there's more in there.

anyway, here's next problem. how access, example object1.x in array, using loop?

for (var j = 0; j < myarray.length; j++){  console.log(myarray[j.x]);  } 

this returns "undefined." again console log outside loop tells me objects have values "x". how access these properties in loop?

i recommended elsewhere use separate arrays each of properties, want make sure i've exhausted avenue first.

thank you!

use foreach built in array function

yourarray.foreach( function (arrayitem) {     var x = arrayitem.prop1 + 2;     alert(x); }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -