accessing an array within an object javascript -
i have following object:
myobject: { myarray1: [1,2,3], myarray2: [4,5,6], myarray3: [7,8,9] } this object keeps growing in arrays(dynamic array?). need figure out method access it. came across using for( var key in myobject) this:
(var key in myobject) { var obj = myobject[key]; (var prop in obj) { //thinking print first value of array console.log(prop[0]); } } but doesn't work prints undefined. know using in not way access object correctly. i'm wondering if suggest method access values of object through loop.
thanks!
iterating object for..in okay, not array. because when sue for..in array, not array values, array indices. so, should doing this
for (var key in myobject) { var currentarray = myobject[key]; for(var = 0; < currentarray.length; += 1) { console.log(currentarray[i]); } }
Comments
Post a Comment