You might want to add an item to the beginning of the array.
In this case you can use the unshift()
method:
const fruits = ['banana', 'pear', 'apple']
fruits.unshift('orange')
fruits //[ 'orange', 'banana', 'pear', 'apple' ]
You might want to add an item to the beginning of the array.
In this case you can use the unshift()
method:
const fruits = ['banana', 'pear', 'apple']
fruits.unshift('orange')
fruits //[ 'orange', 'banana', 'pear', 'apple' ]