0

Arrays to be merged

var longitudeArray = [];
var latitudeArray = [];

I'm trying to merge the two arrays above to make a third array called locations to access it like the example below to display markers on Google Maps. Any ideas how to merge them both?

position: new google.maps.LatLng(locations[i][1], locations[i][2]),
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
Yash
  • 33
  • 1
  • 4
  • _"Any ideas how to merge them both?"_ What is with your own ideas? What have you tried so far? – Andreas Nov 11 '17 at 07:59
  • You'd want an array of arrays/multidimensional array. https://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript – Gry- Nov 11 '17 at 07:59
  • I've tried the concat method but didn't work. – Yash Nov 11 '17 at 08:00
  • Then show your script and we can try to fix it. SO is not meant as a "write me a script"-service... – Andreas Nov 11 '17 at 08:03

2 Answers2

1

You could make use of the map function:

var latLng = latitudeArray.map(function(latitude, index){
    return [latitude, longtitudeArray[index]];
}); 
Christos
  • 53,228
  • 8
  • 76
  • 108
0
var locations = []
for (var i = 0; i < longitudeArray.length; i++) {
  locations[i] = [longitudeArray[i],latitudeArray[i]];
}
Flash Thunder
  • 11,672
  • 8
  • 47
  • 91