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

后端 未结 7 1760
悲哀的现实
悲哀的现实 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:11

    This should do the trick.

    var a1 = ['a', 'e', 'f'];
    var a2 = ['b', 'c', 'd'];
    
    a1.concat(a2, a1.splice(1,a1.length-1)) // [a, b, c, d, e, f]
    

提交回复
热议问题