Learn
Arrays
The .push() Method
What is the .push()
Method?
The .push()
method allows us to easily add elements to the end of an array. It modifies the original array and returns the updated length of the array.
Syntax
- The
.push()
method adds elements to the end of an array. - It can accept multiple elements separated by commas.
- The original array is modified and the new length is returned.
Examples
Let's take a look at a few examples to better understand how the .push()
method works:
Instructions
1.
Create a variable called newNumber
and assign it a value of 4.
2.
Use the .push()
method to add the value of newNumber
to the numbers
array.
3.
Print the updated numbers
array to the console.
Sign up to start coding
Already have an account?
Sign In
Course content