Javascript examples for Array Operation:Array Element
switching two items in an array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/* ww w . ja v a2 s . c o m*/ var my_array = [1, 2, 3, 4, 5, 6]; var swapArrayPosition = function (array, index_1, index_2) { var temp = array[index_1]; array[index_1] = array[index_2]; array[index_2] = temp; } swapArrayPosition(my_array, 4, 1); console.log(my_array); }); </script> </head> <body> </body> </html>