(1)splice
会改变原来是数组,splice(start,length)
var a=[1,2,3];
var b=a.splice(2,1);
b===[3]
a===[1,2]
(2)slice
会构建新数组,slice(start,end)
var a =[1,2,3];
var b=a.slice(2,3);
b===[3]
a===[1,2,3]
(1)splice
会改变原来是数组,splice(start,length)
var a=[1,2,3];
var b=a.splice(2,1);
b===[3]
a===[1,2]
(2)slice
会构建新数组,slice(start,end)
var a =[1,2,3];
var b=a.slice(2,3);
b===[3]
a===[1,2,3]
本文标题:[JavaScript] splice与slice
本文链接:https://www.haomeiwen.com/subject/vyjnkttx.html
网友评论