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

2021-05-31 17:00

阅读:788

标签:rac   lex   title   adr   array   flex   racket   data-   wrapper   

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的删除、截取、插入、替换

标签:rac   lex   title   adr   array   flex   racket   data-   wrapper   

原文地址:https://www.cnblogs.com/wwxdxgb/p/14636291.html


评论


亲,登录后才可以留言!