AreWe

Array move

Jun 29th, 2020
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const moveElement = (from, to, array) => {
  2.     array.splice(to, 0, array.splice(from, 1)[0]);
  3. };
  4.  
  5. let array = [ 0, 1, 2, 3, 4, 5 ];
  6. moveElement(0, 2, array);
  7. console.log(array);
Advertisement
Add Comment
Please, Sign In to add comment