You can join multiple arrays by using concat()
, which does not mutate the original arrays:
const a = [1, 2]
const b = [3, 4]
a.concat(b) //[1,2,3,4]
a //[1,2]
b //[3,4]
You can also use the spread operator:
const c = [...a, ...b]
c //[1,2,3,4]