What does push mean in javascript

藏色散人
Release: 2021-10-18 14:31:47
Original
4933 people have browsed it

The push method in JavaScript can add one or more elements to the end of the array and return the new length. Its usage syntax is such as "array.push(item1, item2, ..., itemX)".

What does push mean in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer

What does push in javascript mean?

JavaScript push() method

push() method adds one or more elements to the end of the array and returns the new length.

Note: New elements will be added at the end of the array.

Note: This method changes the length of the array.

Tip: Please use the unshift() method to add elements at the beginning of the array.

All major browsers support push().

Syntax

array.push(item1, item2, ..., itemX)
Copy after login

Parameter values

Parameters

item1, item2, ..., itemX Required. The element to add to the array.

Return value

Number New length of array

Example

Add more than one element

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi","Lemon","Pineapple")
Copy after login

The above example will output

Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple
Copy after login

Recommended study: "javascript basic tutorial"

The above is the detailed content of What does push mean in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template