Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Popping and Pushing

When dealing with arrays, it’s simple to both remove elements and add new ones.

This is achieved through “popping,” which involves removing items from an array, and “pushing,” which involves adding items into an array.

JavaScript Array pop()

The pop() method eliminates the last element from an array.

Example

const fruits = [“Banana”“Orange”“Apple”“Mango”];
fruits.pop();

The pop() method returns the value that was removed from the array.

Example

const fruits = [“Banana”“Orange”“Apple”“Mango”];
let fruit = fruits.pop();

JavaScript Array push()

The push() method appends a new element to the end of an array.

Example

const fruits = [“Banana”“Orange”“Apple”“Mango”];
fruits.push(“Kiwi”);

The push() method returns the updated length of the array.

Example

const fruits = [“Banana”“Orange”“Apple”“Mango”];
let length = fruits.push(“Kiwi”);