Code Editor

JavaScript has a surprise for us: it has built in functions for arrays that help us do common tasks! Let's learn two of them.

First, push() allows us to add items to the end of an array. Here is an example of how this is used:

var bucketList = ['item 0', 'item 1', 'item 2']; bucketList.push('item 3', 'item 4');

The method push() would make the bucketList array look like:

['item 0', 'item 1', 'item 2', 'item 3', 'item 4'];

Check out how push() works here:

  1. It connects to bucketList with a period.

  2. Then we call it like a function. That's because push() is a function and one that JavaScript allows us to use right on an array.

Connecting a function like this is common in JavaScript. Think: we've been connecting .log to console this whole time!

Report a Bug
If you see a bug or any other issue with this page, please report it here.