How to Merge Arrays in JavaScript in 30 seconds

Опубликовано: 16 Март 2021
на канале: Ado Kukic
1,843
103

Learn how to merge multiple arrays in JavaScript using the spread (...) operator.

You can merge any number of arrays by creating a new array and spreading existing arrays into the newly created array.

For example:

let friends = ["Megan", "Chris"]
let newFriends = ["Sarah", "Sam"]
let oldFriends = ["Sam", "Ryan"]

// to combine all of these into a single array
let allFriends = [...friends, ...newFriends, ...oldFriends]

Happy coding :)