0

I'm trying to populate data for markers on map. I can get it to work using static content but I would like to set sites content by reading from an array.

var sites = [ ['User 1', 45.4210328, -75.6900218, 4], ['User 2', 40.315939, -105.440630, 2], ['User 3', 43.785890, -101.90175, 1], ['User 4', 39.99948, -105.28370, 3] ]; setMarkers(map, sites); 

I tried this

for (var i = 0, len = arr.length; i < len; i++) { var sites = [ [arr[i].username, arr[i].latitude, arr[i].longitude, i ]; } 

but as a result sites only contain one array i.e. the last array. Not all the arrays. How can I create multi-dimensional array within sites?

1
  • as a side note: your code now contains a syntax error (extra [ or missing ]) Commented Jun 16, 2016 at 2:58

1 Answer 1

1

Try this:

var sites = []; for (var i = 0, len = arr.length; i < len; i++) { sites.push([arr[i].username, arr[i].latitude, arr[i].longitude, i]); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.