new Array.push()
时间: 2023-11-07 16:05:27 浏览: 116
js代码-006 面试题---Array.prototype.push的理解
The Array.push() method is used to add one or more elements to the end of an array and returns the new length of the array. It modifies the original array and does not create a new array.
Syntax:
array.push(item1, item2, ..., itemN)
Parameters:
item1, item2, ..., itemN: The elements to be added to the end of the array.
Return value:
The new length of the array after the elements have been added.
Example:
let fruits = ['apple', 'banana', 'orange'];
let newLength = fruits.push('mango', 'kiwi'); // adds two elements to the end of the array
console.log(fruits); // Output: ['apple', 'banana', 'orange', 'mango', 'kiwi']
console.log(newLength); // Output: 5
阅读全文