How to use unshift()?

const words = ['will', 'rock', 'you!']

// output ['will', 'rock', 'you!']
console.log(words)

// returns 4
words.unshift('We')

// output ['We', 'will', 'rock', 'you!']
console.log(words)
Copy

December 5th, 2019

# Add items to the beginning of an array

Add to bookmarks

unshift() adds items to the beginning of an array and returns the length of the new array.

HomeBookmarks