Array push it. push it real good.

Array.push

So far, you've learned about arrays and what it means to mutate an array. In this reading, you will learn about how to change the length of the array by adding new elements to the end of the array.

One way you can do this is by assigning a value at the index equal to the length of the array.

For example:

        
let arr = ['a', 'b', 'c'];
console.log(arr.length); // 3
arr[arr.length] = 'd';
console.log(arr);        // ['a', 'b', 'c', 'd']
console.log(arr.length); // 4
        
    

However, there is an easier way to do this using an Array method.

Easily add an element to the end of an array

There are several Array methods that can mutate the array by adding or removing elements from the array.

Array.push is one of those methods. See how the Array.push method works on MDN.

When you call .push(ele) on an array, it will mutate the array by adding the ele to the end of the array and increase the length of the array by 1.

For example:

        
let arr = ['a', 'b', 'c'];
console.log(arr.length); // 3
arr.push('d');
console.log(arr);        // ['a', 'b', 'c', 'd']
console.log(arr.length); // 4
        
    

This is a useful, shorthand way for adding an element to the end of an array.