### [小程序push怎么用](https://www.prosaas.cn/article/16741) **Published:** 2020-04-03T01:01:45 **Author:** 5201314 **Excerpt:** 小程序中push()方法可向数组的末尾添加一个或多个元素,并返回新的长度。push遇到数组参数时,把整个数组参… ![](https://img.php.cn/upload/article/000/000/039/5e8688e645edc506.jpg) 小程序中push()方法可向数组的末尾添加一个或多个元素,并返回新的长度。push遇到数组参数时,把整个数组参数作为一个元素。 语法 arrayObject.push(newelement1,newelement2,....,newelementX) push和concat二者功能很相像: var arr = \[\]; arr.push(1); arr.push(2); arr.push(\[3, 4\]) arr.push(5, 6); arr = arr.concat(7); arr = arr.concat(\[8, 9\]); arr = arr.concat(10, 11); for(var i in arr){ console.log(i+"-----"+arr\[i\]); } 打印结果如下: > index.js \[sm\]:180 0-----1 > > index.js \[sm\]:180 1-----2 > > index.js \[sm\]:180 2-----3,4 > > index.js \[sm\]:180 3-----5 > > index.js \[sm\]:180 4-----6 > > index.js \[sm\]:180 5-----7 > > index.js \[sm\]:180 6-----8 > > index.js \[sm\]:180 7-----9 > > index.js \[sm\]:180 8-----10 > > index.js \[sm\]:180 9-----11 推荐:《小程序开发教程》 以上就是小程序push怎么用的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** 后端开发 ---