Here I have two arrays and I need to transform first array to be in format like second array...
First array is driving directions from google map so:response.routes[0].overview_path produce something like:
An array of LatLngs representing the entire course of this route. The path is simplified in order to make it suitable in contexts where a small number of vertices is required (such as Static Maps API URLs). CODE
[ new google.maps.LatLng(12.34, 56.789), new google.maps.LatLng(87.65, 123.45) ] so I have this:
[ [56.789, 12.34], [123.45, 87.65] ] and I need to trasform this array with javascript in this format:
[ [ { X: 12.34 Y: 56.789 }, { X: 87.65, Y: 123.45 } ] ] So how I can do this? Is there any way? How to transform first array to in format like second with X and Y?
UPDATE: I do this:
tacke = response.routes[0].overview_path; rezultat = [tacke.map(function(w) { return {X:w[1], Y:w[0]}; })]; and now console.log(rezultat); produce this code:
console.log(rezultat); [Array[220]] 0: Array[220] [0 … 99] 0: Object X: undefined Y: undefined __proto__: Object 1: Object X: undefined Y: undefined __proto__: Object 2: Object X: undefined Y: undefined __proto__: Object Why here is X and Y undefinded...
DEMO:http://jsbin.com/uTATePe/41 CODE:http://jsbin.com/uTATePe/41/edit