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 ]
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便