The push()
method is used to insert items inside the array.
array.push(value)
The push()
method attaches to the right side of an array with the .
operator. The push method inserts item to the right side of the array.
const fruits = ['apple'];
fruits.push('mango');
console.log(fruits); // Prints: [ 'apple', 'mango' ]
fruits.push('banana');
console.log(fruits); // Prints: [ 'apple', 'mango', 'banana' ]
We can see that the push()
method inserts an item at the end of the array.