Blogger Information
Blog 10
fans 0
comment 0
visits 10430
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组splice操作
亘古匆匆的博客
Original
815 people have browsed it

js数组中的splice方法可谓是一个万能的方法,它既可以用来添加元素,也可以用来删除元素

甚至可以用来替换元素

假设我们有一个数组a

var a=[1,2,3,4,5,6];

a.splice(2,3);它的意思就是从第二个位置删除三个元素,所以此时数组元素为1,2,6

a.splice(2,0,'a','b','c');这样写的意思就是从第二个位置开始,删除0个元素,并添加a,b,c三个元素,

所以数组此时为1,2,a,b,c,3,4,5,6;

a.splice(2,2,,'a','b');这样就是从第二个位置删除两个元素,再添加两个元素,就实现了数组元素的替换

此时的数组元素就成了1,2,a,b,5,6;

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!