0
I’m trying to build an Object Array in Javascript, but the result is not as expected.
That’s how I’d like it to stay:
But this is how it’s getting:
That’s the code I’m using:
var wo = new Array();
while ( listItemEnumerator.moveNext() )
{
var oListItem = listItemEnumerator.get_current();
wo.push( { ID: oListItem.get_id(), Status: oListItem.get_item( 'Status' ) } );
}
I need the Object Array to be built inside the WHILE
Someone can help me?
I did not understand the difference between the expected and the obtained result. Could I explain better? Suggestion: instead of doing
console.log(wo)
, doconsole.log(JSON.stringify(wo))
and see what the real difference is between the expected and the obtained. Because at first glance, your code seems correct... P.S. Related question– mgibsonbr
looks like he’s building an Object Object instead of Object Array.. I’ll test your command
– Lugarini
@Thiago, your array seems to be correct, check your result again.
– Fernando Leal
@Thiago Both screenshots show arrays. In one case, the array is very large, so it was represented by
Array[32]
. On the other, he fits the line, so he was represented by[Object,Object,Object...]
. But both are arrays even, internally there is no difference at all. By the way, if you are not familiar with arrays literals, I suggest you read the related question.– mgibsonbr
really has no difference anyway, in both ways this creating an array of objects...
– Lugarini