Javascript中的Slice和Splice方法之间的低级差异
slice和splice之间的基本区别是-
splice()更改在其上调用它的原始数组,并以新数组对象的形式返回数组中已删除的项目。
slice()不会更改原始数组,并且还会返回切片的数组。
示例
// splice changes the array
let arr = [1, 2, 3, 4, 5];
console.log(array.splice(2));
//切片不会更改原始切片
let arr2 = [1, 2, 3, 4, 5];
console.log(array2.slice(2));
console.log("\n After Changing the arrays");
console.log(array);
console.log(array2);输出结果
[ 3, 4, 5 ] [ 3, 4, 5 ]
更改数组后
[[ 1, 2 ] [ 1, 2, 3, 4, 5 ]
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短