Note that there are some explanatory texts on larger screens.

plurals
  1. POArrays transformation
    text
    copied!<p>Here I have two arrays and I need to transform first array to be in format like second array...</p> <p>First array is driving directions from google map so:<code>response.routes[0].overview_path</code> produce something like:</p> <pre><code>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></pre> <p>CODE</p> <pre><code>[ new google.maps.LatLng(12.34, 56.789), new google.maps.LatLng(87.65, 123.45) ] </code></pre> <p>so I have this:</p> <pre><code>[ [56.789, 12.34], [123.45, 87.65] ] </code></pre> <p>and I need to trasform this array with javascript in this format:</p> <pre><code>[ [ { X: 12.34 Y: 56.789 }, { X: 87.65, Y: 123.45 } ] ] </code></pre> <p>So how I can do this? Is there any way? How to transform first array to in format like second with X and Y?</p> <p><strong>UPDATE:</strong> I do this:</p> <pre><code>tacke = response.routes[0].overview_path; rezultat = [tacke.map(function(w) { return {X:w[1], Y:w[0]}; })]; </code></pre> <p>and now <code>console.log(rezultat);</code> produce this code:</p> <pre><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 </code></pre> <p>Why here is X and Y undefinded...</p> <p>DEMO:<a href="http://jsbin.com/uTATePe/41" rel="nofollow">http://jsbin.com/uTATePe/41</a> CODE:<a href="http://jsbin.com/uTATePe/41/edit" rel="nofollow">http://jsbin.com/uTATePe/41/edit</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload