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

后端 未结 7 1799
悲哀的现实
悲哀的现实 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条回答
  •  梦毁少年i
    2020-12-29 05:25

    private moveElements(source: Array, target: Array) {
        target.push(...source);
        source.splice(0, source.length);
        //or
        [].push.apply(target,source);
        source.splice(0, source.length);
    }
    

提交回复
热议问题