I have an existing multidimensional associative array with this structure. It has 3 elements. Each of the subarrays has 3 elements.
{"id":"723419","lat":33.217,"lon":-92.817,"dist":1437.15733534053},
{"id":"723424","lat":33.567,"lon":-91.717,"dist":1902.4556686060116},
{"id":"722447","lat":32.383,"lon":-94.717,"dist":2317.6870313059217},
I want to create another (temp) array with 3 elements, and loop through the array, adding an element to each subarray so that each subarray will have 4 elements:
{"id":"723419","lat":33.217,"lon":-92.817,"dist":1437.15733534053,"elev":abc},
{"id":"723424","lat":33.567,"lon":-91.717,"dist":1902.4556686060116,"elev":def},
{"id":"722447","lat":32.383,"lon":-94.717,"dist":2317.6870313059217,"elev":ghi},
so far, I've tried to loop through my temp array
for (var i in tempArray) { //loop through locations returned with elevation data
multiArray[i]['elev']=...
}
and treated it as an object (even though I declared the multi array as an Array()
for (var i in tempArray) { //loop through locations returned with elevation data
multiArray.i.append(elev)=...
}
Both ways, JS complains that multiArray[i] doesn't exist. From what I know about JS, this should work.
Thanks for the help
for .. into loop through arrays in JavaScript, it's the Wrong Thing (use a regularforloop fromi = 0toarray.lengthinstead). Also, those are objects, not associative arrays. Whether you useArray()or[]to declare it does not make any technical difference, but you should always use[].