Guest User

Untitled

a guest
Jan 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. const animals = ["elephant", "monkey", "snake", "lion"];
  2.  
  3. const positionToAddNewItem = 2;
  4.  
  5. for (let index = animals.length; index > positionToAddNewItem; index--) {
  6. animals[index] = animals[index - 1];
  7. }
  8.  
  9. animals[positionToAddNewItem] = "macaw";
  10.  
  11. console.log(animals); // will return: [ 'elephant', 'monkey', 'macaw', 'snake', 'lion' ]
Add Comment
Please, Sign In to add comment