Advertisement
CR7CR7

moveElements

Sep 18th, 2022
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let array1 = [1, 2, 3, 4, 5, 6, 7];
  2. let array2 = [];
  3.  
  4. let moveCount = 3;
  5.  
  6. console.log(`Before element movement.`);
  7. console.log(array1);
  8. console.log(array2);
  9.  
  10. for (let i = 0; i < moveCount; i++) {
  11.   let movedElement = array1.pop();
  12.   array2.push(movedElement);
  13. }
  14.  
  15. console.log(`After element movement.`);
  16. console.log(array1);
  17. console.log(array2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement