Mike Cuddy Mike Cuddy - 3 months ago 22
Javascript Question

Javascript objects and arrays issue

I am working on a project and I am stuck at a point that I did not think was that hard. I have an array that looks like the following:

var Coords = [
{lat: 7, lng: 3},
{lat: 3, lng: 2}
]


I need to use a loop to push more lat and lng coordinates into this array...actually about 30,000 more coordinates. (Please note that the current data in there is an example.) I have tried doing:

Coords.push(Coords[2].lat = 100)
Coords.push(Coords[2].lng = 200)


and that does not help. Any help, with this simple problem would be great! I can figure out the loop just need to know how to get data in!!

Answer

Just use

Coords.push({lat: 1, lng: 2})

for pushing new data and

Coords[1].lat = 2

for modifying data.

Comments