Blogger Information
Blog 7
fans 0
comment 0
visits 8110
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
splice()的用法
dongfeng的博客
Original
2194 people have browsed it

 

js数组的常用函数(splice())

 1,删除:用于删除元素,两个参数,第一个参数(要删除第一项的位置)第二个参数(要删除的项数)
 2,插入:向数组指定位置插入任一项元素,3个参数。1 起始位置,2 。0.3 要插入的项
 3替换:向数组指定位置插入任一项元素,同时删除任意数的项,3个参数。1 起始 2 删除的项,3处输入的任意的选哪个
 

2.插入-向数组指定位置插入任意项元素。三个参数,第一个参数(起始位置),第二个参数(0),第三个参数(插入的项数) 
3.替换-向数组指定位置插入任意项元素,同时删除任意数量的项,三个参数。第一个参数(起始位置),第二个参数(删除的项数),第三个参数(插入任意数量0

var dxf =[];
dxf.push(1);
dxf.push(2);
dxf.push(3);
console.log(dxf);
dxf.splice(0,1);
console.log(


var dxf = [];
        dxf.push(1);
        dxf.push(2);
        dxf.push(3);
        console.log(dxf); // [1, 2, 3]
       
        // 删除
        dxf.splice(0,1);  

        console.log(dxf); // [2,3]
        dxf.splice(0,2); 

        console.log(dxf); 
        
        //替换
        dxf.splice(0,1,4);

        console.log(dxf);  
        dxf.splice(0,2,4); 
        console.log(dxf);  
        
        //添加
        dxf.splice(1,0,5); 
        console.log(dxf);    

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post