0

I have an array within an array as follows:

var array = new Array();

for ( i = 0; i < start.length; i++) {
   array[i] = {};
   array[i]['properties'] = {};

   for(property in start[i].properties ){
         //start[i].properties[property] --> ['Type'] = 'any string'
         array[j]['properties'][property] = start[i].properties[property];
   }
array[i]['id'] = start[i].getId();

}

So in the end I've an array with different elements like 'id' and an element as an array in this array (properties).

But when I use this array in another function, I can't reference to this inner array:

for (var v = 0; v < array.length; v++) {
   console.log(array[v][properties]['Type'])
}

The "array[v][properties]['Type']" is not defined..... Why?

0

1 Answer 1

3

You're trying to access the variable properties, not the key properties The proper way to do that would be with array[v].properties.Type.

It's also better not to use bracket syntax unless you must - using dot syntax makes for more easily readable code.

The correct term for JavaScript btw is object, not associative array.

Sign up to request clarification or add additional context in comments.

2 Comments

Thx but how do I iterate through all properties?
for(property in array[v].properties){ console.log(array[v].properties.property); } doesn't work.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.