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

后端 未结 7 1762
悲哀的现实
悲哀的现实 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:25
    private moveElements(source: Array<any>, target: Array<any>) {
        target.push(...source);
        source.splice(0, source.length);
        //or
        [].push.apply(target,source);
        source.splice(0, source.length);
    }
    
    0 讨论(0)
提交回复
热议问题