javascript - How to swap values in an array by using Array.prototype.slice.call -


It should be simple, but it is not able to wrap my mind why it is not working: / P>

  function swap values ​​() {var args = Array.prototype.slice.call (logic); Var temp = args [0]; Args [0] = args [1]; Args [1] = temporary; Return temporary; } Var arr = [1,2] swapValues ​​(arr);  

It should swap values ​​- but it is not.

logic is the purpose of logic, so your args [0 ] is [1,2] (first argument), and args [1] is undefined .

You want something like this:

  function swapValues ​​() {var arg = array.protitip.S.S.L.J.L.L. . (Arguments) [0]; Var temp = arg [0]; Arg [0] = Arg [1]; Arg = 1] = temporary; Return ARG; }  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -