title: How to swap values of an array? Javascript
body: <p>I am using <a href="https://leafletjs.com/" rel="nofollow noreferrer">Leaflet</a> and I am trying to create a polyline and marker points but it gives opposite lat and long so I have to swap them. Creating a marker is easy because it only has one pair of lat and long but creating a polyline is complicated because has a lot of points.<br>
  Below is what I am currently using to swap lat and long for marker points.</p>
  <pre><code>var splitObj = objVal.toString().split(&quot;],[&quot;);
  var latlng = splitObj.map(function(x)
      {
          var couple= (/\d+.\d+, \d+.\d+/g).exec(x).toString();
          var splitted = couple.split(&quot;, &quot;);
          return &quot;[&quot;+splitted[1]+&quot;,&quot;+splitted[0]+&quot;]&quot;;
      });
  latlng.join();
  </code></pre>
  <p>Result:</p>
  <blockquote>
  <p>['[[a, b], [c, d], [e, f]]'] // this is the objVal<br>
  expectation:<br>
  ['[[b,a], [d,c], [f,e]]']<br>
  reality:<br>
  ['[b,a]']</p>
  </blockquote>