A better way to splice an array into an array in javascript

前端 未结 8 1819
天命终不由人
天命终不由人 2020-12-02 08:36

Is there a better way than this to splice an array into another array in javascript

var string = \'theArray.splice(\'+start+\', \'+number+\',\"\'+newItemsArr         


        
8条回答
  •  忘掉有多难
    2020-12-02 09:02

    If you don't want to concatenate inserting items to first two parameters of Array.splice(), an elegant way is to use Function.bind() and Function.apply() together.

    theArray.splice.bind(null, startIndex, deleteCount).apply(newItemsArray);
    

提交回复
热议问题