区分split splice slice
每每遇到它们,就傻傻分不清楚
1. split(分割) slice(分割) splice(剪接)
split:String.split(separator,num) -->把字符串分割成字符串数组,返回字符串数组,
slice:arrayObject.slice(start,end) -->返回一个新的子数组,不会改变原数组
splice:arrayObject(start ,num,item,item...)-->用于插入、删除或替换数组的元素。
从第2个位置开始,删除一个元素,添加2个元素
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,1,"Lemon","Kiwi");
console.log(fruits) ---> ["Banana", "Orange", "Lemon","Kiwi", "Mango"];
从第二个位置删除2个元素
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,2);
console.log(fruits) --->["Banana", "Orange"]