javascript - associative array inside array -
i have array within array follows:
var array = new array(); ( = 0; < 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 end i've array different elements 'id' , element array in array (properties).
but when use array in function, can't reference inner array:
for (var v = 0; v < array.length; v++) { console.log(array[v][properties]['type']) }
the "array[v][properties]['type']" not defined..... why?
you're trying access variable properties
, not key properties
proper way array[v].properties.type
.
it's better not use bracket syntax unless must - using dot syntax makes more readable code.
the correct term javascript btw object, not associative array.
Comments
Post a Comment