Techstacker
Light ModeDark ModeReset dark mode. Falls back to OS dark mode setting.

Pages

No results for 'undefined'

Blog Posts

No results for 'undefined'
Powered by Algolia

JavaScript Array Methods, Add and Remove Items from Array

Sep 26, 20171 min readJavaScriptViews:

The four Array Methods we use:

  • unshift() adds item to the beginning of array.
  • shift() removes first item in array.
  • push() adds item to the end of array.
  • pop() removes last item of array.

I use the Chrome DevTools Console in the example.

Shortcuts to open the console: Cmd + Option + j on Mac, or Ctrl + Shift + j on Windows. Or just right click in your browser window and click on Inspect. Then click on the console tab.

Code for the initial array we use in the example:

var list = ['item 1', 'item 2', 'item 3']