Blogger Information
Blog 35
fans 0
comment 0
visits 25288
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
forEach与splice使用示范--2019年5月7日22时05分
白守的博客
Original
946 people have browsed it

  1. 使用forEach()遍历数组

实例

    <script>
        // 设置一个初始化数组
    var i = [1,2,3,4,5,6,7,8,9];
    // 使用foreach来查看数组内容
    i.forEach(function(value,key,array){
        // key=键 value=值
        document.write('['+key+ ']'+ '=>' + value+ '<br>' );
    });
    </script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

2. 实现数组元素的添加, 删除和更新操作

实例

    <script>
         // 设置一个初始化数组
    var i = [1,2,3,4,5,6,7,8,9];

    // i.splice(从哪里开始,删除多少个,增加什么)
    i.splice(1,0,'增加一个','2','3')
    // splice,增,2,'2123'
    // 第一个开始,删除两个,就是 1xx45678//就是删除了2,3
    i.splice(1,2)
    // 删除第一第二个,然后增加两个,这样可以做到替换
    i.splice(0,2,'wd','pw',)
    </script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

Correction status:Uncorrected

Teacher's comments:
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