split:=>字符串变成数组
let str = 'fdsafsdafadsfasdfadsfsdahghgfhgh';
console.log(str.split("a"),"字符串的split");
slice:截取
参数为索引值,包前不包后;没改变原数组;返回一个新的数组
let arr = [2, 'a', 3, 'b', 4, 'dfasf', 3,"fasfdsa",3];
//slice[start,end)
console.log(arr.slice(1,2),"数组的slice");
console.log(arr,"数组");
splice:指定位置的增删改
参数:索引,元素个数,增加的元素;(包前不包后)
返回值:删除时,返回删掉的值;增加元素时,返回空数组;
有该变原数组
let arr = [2, 'a', 3, 'b', 4, 'dfasf', 3,"fasfdsa",3];
//从索引值位置开始删除2个元素
console.log(arr.splice(1,2),"数组的splice");
//从索引值位置增加一个元素
console.log(arr.splice(0,0,"感谢抗疫的所有一线人员"))
console.log(arr,"数组");