小程序中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—–1index.js [sm]:180 1—–2index.js [sm]:180 2—–3,4index.js [sm]:180 3—–5index.js [sm]:180 4—–6index.js [sm]:180 5—–7index.js [sm]:180 6—–8index.js [sm]:180 7—–9index.js [sm]:180 8—–10index.js [sm]:180 9—–11
推荐:《》
以上就是小程序push怎么用的详细内容,更多请关注GTHOST其它相关文章!