0

I am wondering if there is any difference between these two methods to push to array in javascript knowing that they both will create new array.

const arr0 = [obj1, obj2, obj3];
const arr1 = arr0.concat(obj4);    // method 1
const arr2 = [...arr0, obj4];      // method 2
Elnoor
  • 3,401
  • 4
  • 24
  • 39

1 Answers1

1

a=[1] a.concat([2,3]) will give [1,2,3] whereas [...a,[2,3]] gives [1,[2,3]]. For more info checkout this answer (spread operator vs array.concat())

Mohit Singh
  • 498
  • 4
  • 10