Example
Add a new item to an array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
The result of fruits will be:
Banana,Orange,Apple,Mango,Kiwi
Definition and Usage
The push() method adds new items to the end of an array, and returns the new length.
Note: The new item(s) will be added at the end of the array.
Note: This method changes the length of the array.
Syntax
array.push(item1, item2, ..., itemX)
Parameter Values
Parameter Description
item1, item2, ..., itemX Required. The item(s) to add to the array
Example
Add more than one item:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");
The output of the code above will be:
Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple
No comments:
Post a Comment