在数组 arr 的 index 处添加元素 item。不要直接修改数组 arr,结果返回新的数组

添加元素

https://www.nowcoder.com/practice/941bcfa5b87940869fda681c1597fd3a?tpId=6&tqId=10958&tPage=1&rp=1&ru=/ta/js-assessment&qru=/ta/js-assessment/question-ranking

function insert(arr, item, index) {

var temp = arr.slice(0);
temp.splice(index,0,item);
return temp;

/*
var temp = [],res = [];
temp.push(arr.slice(0,index));
res.push(arr.slice(index));
temp.push(item);
return temp.concat(res);
*/

}

全部评论

相关推荐

牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务