Add a new item to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Try it Yourself »
Add two new items to the array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon");
Try it Yourself »
The push()
method adds new items to the end of an array.
The push()
method changes the length of the array.
The push()
method returns the new length.
array.push(
item1,
item2, ...,
itemX)
Parameters | Description |
item1 item2 .. itemX |
The item(s) to add to the array. Minimum one item is required. |
Type | Description |
A number | The new length of the array. |
Add 3 items to the array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");
Try it Yourself »
push()
returns the new length:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Try it Yourself »
push
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!