Is there a way to use Array.splice in javascript with the third parameter as an array?

后端 未结 7 1797
悲哀的现实
悲哀的现实 2020-12-29 04:30

I\'m attempting the following:

var a1 = [\'a\', \'e\', \'f\'];  // [a, e, f]
var a2 = [\'b\', \'c\', \'d\'];  // [b, c, d]
a1.splice(1, 0, a2);       // expe         


        
7条回答
  •  轮回少年
    2020-12-29 05:23

    With ES6, you can use the spread operator. It makes it much more concise and readable.

    var a1 = ['a', 'e', 'f'];
    var a2 = ['b', 'c', 'd'];
    
    a1.splice(1, 0, ...a2);
    console.log(a1)

提交回复
热议问题