Move or swap element inside an object - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Move or swap element inside an object

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//w  w  w  .  j  av  a  2  s.  co  m
var arr = [0,1,2];
function swapElements(a, x, y){
    var temp = a[x];
    a[x] = a[y];
    a[y] = temp;
}
console.log(arr);
swapElements(arr,0,1);
console.log(arr);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials