push方法
新元素在数组最后,例如往初始数组 test:[{id:"1",value:"1"}]
test.push({id:"2",value:"2"}) ,返回数组为{{id:"1",value:"1",id:"2",value:"2"}}
unshift
新元素在数组开头,还是采用上面test数组
test.unshift({id:"2",value:"2"}),返回数组为{{id:"2",value:"2",id:"1",value:"1"}}
新元素在数组最后,例如往初始数组 test:[{id:"1",value:"1"}]
test.push({id:"2",value:"2"}) ,返回数组为{{id:"1",value:"1",id:"2",value:"2"}}
新元素在数组开头,还是采用上面test数组
test.unshift({id:"2",value:"2"}),返回数组为{{id:"2",value:"2",id:"1",value:"1"}}
本文标题:微信小程序向数组添加新元素,返回新长度
本文链接:https://www.haomeiwen.com/subject/imfbpqtx.html
网友评论