js中splice的删除、截取、插入、替换

var arr =["George","John","Thomas","James","Adrew","Martin"]

let mm = arr.splice(2,3)

console.log(arr)  //  结果  ["George","John","Martin"]    如果arr不赋给某个值,直接使用arr.splice(2,3) ,结果arr就是删除第三位后面的三个元素之后剩余元素组成的数组

console.log(mm)   //  结果  ["Thomas","James","Adrew"]   如果arr赋给某个值,结果mm就是第三位元素后面的三个元素组成的数组。

 

var arr1 =["George","John","Thomas","James","Adrew","Martin"]   

arr1.splice(2,0,"Jack")   [ "George", "John", "Jack", "Thomas", "James", "Adrew", "Martin" ]  // 插入  将新元素插入第三个位置,后面的依次排后

arr1.splice(2,1,"Jack")   [ "George", "John", "Jack", "James", "Adrew", "Martin" ] // 替换    将新元素替换掉第三个元素

 

js中splice的删除、截取、插入、替换

上一篇:weblogic主控登录超时配置


下一篇:CSS-display和visibility