Home  >  Article  >  Web Front-end  >  Learn more about the basics of JavaScript Array objects

Learn more about the basics of JavaScript Array objects

jacklove
jackloveOriginal
2018-05-04 16:17:341410browse

This article will give you some understanding of the Array object in JavaScript.

Array object

The Array object is used to store multiple values ​​in a single variable.

Syntax for creating Array objects:

new Array();
new Array(size);
new Array(element0, element1, ..., elementn);

Parameters

The parameter size is the expected number of array elements. In the returned array, the length field will be set to the value of size.

Parameter element ..., elementn is the parameter list. When the constructor Array() is called with these arguments, the elements of the newly created array are initialized to these values. Its length field will also be set to the number of parameters.

Return value

Returns the newly created and initialized array.

If no parameters are used when calling the constructor Array(), the returned array will be empty and the length field will be 0.

When you call the constructor and only pass it a numeric parameter, the constructor will return an array with the specified number of elements and undefined.

When Array() is called with other parameters, the constructor will initialize the array with the value specified by the parameter.

When the constructor is called as a function without using the new operator, it behaves exactly the same as when it is called with the new operator.

This article provides a detailed understanding of the basic content of Array(). For more Array() related knowledge, please visit the php Chinese website.

Related recommendations:

Array.apply analysis in JavaScript

##Detailed explanation of the relationship between Array and Object in Javascript

Properties and methods of Array (array) in JavaScript

The above is the detailed content of Learn more about the basics of JavaScript Array objects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn