文章 评论 浏览 26
/***
Array.prototype._slice = function(index, num, ...addList) { let newArr = [] let returnItem = [] while(num > 0) { // 起始下标有可能传入负数 if (index < 0) { index += this.length } // 删除当前项 returnItem.push(this[index]) delete this[index] index++ num-- } // 将老数组赋予新数组 for(const item of arr) { if(item) newArr.push(item) } let length = newArr.length for(var i = 0; i< length;i++) { this[i] = newArr[i] } this.length = length // 新增元素 if(addList && addList.length > 0) { for(const item of addList) { this.push(item) } } return returnItem }
@mqyqingfeng 想问一下题主,async/await 到底应该算是 ES7(2016) 还是 ES8 (2017) 呢?
async/await
网上有说是 ES7 的,也有说是 ES8 的 :-)
文章 0 评论 0
接受
/***
*/
第 158 题:如何模拟实现 Array.prototype.splice