What is 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.
.push() method adds elements to the end of an array.
Let's take a look at a few examples to better understand how the
.push() method works:
Create a variable called
newNumber and assign it a value of 4.
.push() method to add the value of
newNumber to the
Print the updated
numbers array to the console.
Sign up to start coding
Already have an account?