DEV Community

Discussion on: 2 Ways to Merge Arrays in JavaScript

Collapse
 
michelloworld profile image
Mic

From example "A. Using Spread"

I think forgot put "..." before "array2"

function combineArray(array1, array2) {
  return [...array1, array2]; // <-------------- HERE
}

const isArray = [1,2,3];
const notArray = 'random';

combineArray(isArray, notArray);
// 😱 [ 1, 2, 3, 'r', 'a', 'n', 'd', 'o', 'm' ]

sorry if i'm wrong.

Collapse
 
samanthaming profile image
Samantha Ming

Ahhhh my mistake 😱 Thank you for letting me know πŸ‘