Append an array to another in JavaScript
Question:
How to append an array to another in JavaScript? Answer:
let myArray1 = [1,2,3];
let myArray2 = [5,6,7];
myArray1 = [...myArray1, ...myArray2];
// myArray1 is [1,2,3,5,6,7]
Description:
JavaScript has multiple ways to concatenate 2 or more arrays into one. You can use concat or push methods, but the simplest solution is the spread operator.
Reference:
JavaScript spread operator reference
Share "How to append an array to another in JavaScript?"
Related snippets:
- Check if an array contains a value
- Append an array to another in JavaScript
- Get the first element of an array in JavaScript
- Convert Map values to array in JavaScript
- Convert array to comma separated string using JavaScript
- Get the minimum value in an array using JavaScript
- Get the maximum value in an array using JavaScript
- Remove duplicates from array in JavaScript
- Split a string into words
- Use foreach in JavaScript
Tags:
append, combine, add, merge, two, multiple, array, Technical term:
Append an array to another in JavaScript