Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Array Methods | Variables and Data Types
course content

Course Content

Introduction to JavaScript

Array MethodsArray Methods

Arrays are versatile for storing and retrieving data. Retrieving data using square brackets [] is called indexing.

However, there are various methods available for working with arrays.

Adding Elements

There are different ways to add elements to an array.

Push

The push() method adds a new value to the end of the array:

Unshift

The unshift() method works like the push() method, but it inserts the value at the beginning of the array.

Indexing

You can append a new value by indexing:

Indexing allows you to assign a value to a specified index, reassign a previous value, and more:

To create a new element in the array without mistakes, you can use the push(value) method or the arr[arr.length] = value expression:

Deleting Elements

Sometimes, you may need to delete elements from an array. This can be done in different ways.

Pop

The pop() method deletes the last element in an array and allows you to save it to another variable:

Shift

The shift() method works like pop(), but it removes the first element from an array:

1. How can we add an element to the end of the array?
2. How can we remove the last element in the array?

question-icon

How can we add an element to the end of the array?

Select a few correct answers

How can we remove the last element in the array?

Select the correct answer

Everything was clear?

Section 2. Chapter 7
course content

Course Content

Introduction to JavaScript

Array MethodsArray Methods

Arrays are versatile for storing and retrieving data. Retrieving data using square brackets [] is called indexing.

However, there are various methods available for working with arrays.

Adding Elements

There are different ways to add elements to an array.

Push

The push() method adds a new value to the end of the array:

Unshift

The unshift() method works like the push() method, but it inserts the value at the beginning of the array.

Indexing

You can append a new value by indexing:

Indexing allows you to assign a value to a specified index, reassign a previous value, and more:

To create a new element in the array without mistakes, you can use the push(value) method or the arr[arr.length] = value expression:

Deleting Elements

Sometimes, you may need to delete elements from an array. This can be done in different ways.

Pop

The pop() method deletes the last element in an array and allows you to save it to another variable:

Shift

The shift() method works like pop(), but it removes the first element from an array:

1. How can we add an element to the end of the array?
2. How can we remove the last element in the array?

question-icon

How can we add an element to the end of the array?

Select a few correct answers

How can we remove the last element in the array?

Select the correct answer

Everything was clear?

Section 2. Chapter 7
some-alt