在数组 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);
*/

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
舂锋:不能投什么岗都用一份简历,一般都是要看企业的岗位需求来写职业技能或者是项目经历,跟岗位相关的就写多一点。
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

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