Home >WeChat Applet >Mini Program Development >How to use mini program push

How to use mini program push

尚
Original
2020-04-03 09:01:458999browse

How to use mini program push

The push() method in the applet can add one or more elements to the end of the array and return the new length. When push encounters an array parameter, it treats the entire array parameter as one element.

Syntax

arrayObject.push(newelement1,newelement2,....,newelementX)

The functions of push and concat are very similar:

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]);
}

The printing result is as follows:

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

Recommendation: " Mini Program Development Tutorial"

The above is the detailed content of How to use mini program push. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn