本文共 859 字,大约阅读时间需要 2 分钟。
push() method is used adds/inserts an element at the end of an array, it returns nothing but changes the length of the array.
push()方法用于在数组末尾添加/插入元素,它只返回改变数组的长度,什么也不返回。
Syntax:
句法:
array_name.push(element1, element2, ...);
It accepts one or more than one elements and inserts to the end of the array and changed the length of an array.
它接受一个或多个元素,然后插入到数组的末尾并更改数组的长度。
Examples:
例子:
Input: var countries = ["INDIA", "USA"]; Function call: countries.push("UK"); countries.push("CANADA", "RUSSIA"); Output: "INDIA", "USA", "UK", "CANADA", "RUSSIA"
JavaScript Code to demonstrate example of Array.push() method
JavaScript代码演示Array.push()方法的示例
JavaScipt Example
Output
输出量
countries: INDIA,USAlength is: 2countries: INDIA,USA,UKlength is: 3countries: INDIA,USA,UK,CANADA,RUSSIAlength is: 5
翻译自:
转载地址:http://ayazd.baihongyu.com/