What is the most elegant way for js to add another array to the end of the array?

is there a method like push, but instead of inserting an element into an array, add another array
similar to java"s addAll method

all I know so far is concat, but he returns the new array instead of making changes on the original array,

Mar.06,2021

let arr = [1, 2];
arr.push(...[3, 4]);

if you use the ES6, method, you should be able to push (.newarr)


there are about three things I know:

  • a.concat (b)
  • Array.prototype.push.apply (a, b)
  • a.push (.b)

what do you mean by this elegant standard


let arr = [1 hr class= 2 answer 3]
[] .push.apply (arr, [4je 5J 6])


the most elegant thing should be the direct extension operator ~:

const d = ['1','2'];
const x = ['3','4'];
const a = [...d, ...x];
Menu