Skip to content

Instantly share code, notes, and snippets.

@saifsmailbox98
Last active June 24, 2017 22:09
Show Gist options
  • Select an option

  • Save saifsmailbox98/741a66dafb4bd7315974e82fead0916d to your computer and use it in GitHub Desktop.

Select an option

Save saifsmailbox98/741a66dafb4bd7315974e82fead0916d to your computer and use it in GitHub Desktop.

You first need to insert the item to the end of the array arr using the method push() on the array arr. And then remove and return the first element of the array using shift() method on the array arr.

  • push(): Add items to then end of an array. push() returns the new array length.
  • shift(): Remove an item from the beginning of an array. shift() returns the removed item.
  • pop(): Remove an item from the end of an array. pop() returns the removed item.
  • unshift(): Add items to the beginning of an array. unshift() returns the new array length.
var myArray = [1,2,3,4,5];

myArray; //[1,2,3,4,5]

myArray.push(8); // 6 (new length)

myArray; //[1,2,3,4,5,8]

myArray.shift(); // 1 (removed item)

myArray; // [2,3,4,5,8]

💬

@saifsmailbox98
Copy link
Copy Markdown
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment