Blogger Information
Blog 61
fans 1
comment 0
visits 69768
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0507-splice()用法
我的博客
Original
813 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>splice</title>
</head>
<body>
<script>
    var items=['php','html','java','c++','python','jack','marry','exe','dia'];
    items[0]='css';
    document.write(items + '<br>'); //修改了items[0]的值,把'php'换成了'css'

    /*array.splice(删除或增加的位置开始数字,增加或删除位置的结束位置数字/0为不删除只增加,要增加或替换的元素)*/
    items.splice(1,0,'array');      //向数组items[1]的位置增加一个元素'array',原来1的位置元素自动后移。
    document.write(items + '<br>');
    items.splice(2,1);              //从低2个元素开始删除1个位置的元素。
    document.write(items + '<br>');
    items.splice(1,2,'peter');      //删除从第一个开始往后2个元素,在第1的位置增加'peter'
    document.write(items + '<br>');

</script>



</body>
</html>

运行实例 »

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


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
Author's latest blog post