JavaScript Array push()
陣列 (array) 的 push()
方法用來新增元素到陣列最後面。
語法:
ary.push([element1[, ...[, elementN]]])
push() 方法會返回陣列新的長度。
用法:
var fruits = ['Apple', 'Banana'];
fruits.push('Orange');
// 輸出 ["Apple", "Banana", "Orange"]
console.log(fruits);
var sports = ['soccer', 'baseball'];
var total = sports.push('football', 'swimming');
// 輸出 ["soccer", "baseball", "football", "swimming"]
console.log(sports);
// 輸出 4
console.log(total);