JavaScript Object -- Array

Source: Internet
Author: User

Array object

Array objects are used to store multiple values in a single variable.

Syntax for creating an Array object:

New Array ();

New Array (size );

New Array (element0, element1,..., elementn );

Parameters

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

Element..., elementn is the parameter list. When these parameters are used to call the constructor Array (), the elements of the newly created Array are initialized to these values. Its length field is also set to the number of parameters.

Return Value

Returns the newly created and initialized array.

If no parameter is used when the constructor Array () is called, the returned Array is empty and the length field is 0.

When a constructor is called, only one numeric parameter is passed. The constructor returns an array with a specified number and an undefined element.

When other parameters call Array (), the constructor initializes the Array with the value specified by the parameter.

When a constructor is called as a function without the new operator, its behavior is exactly the same as that when the new operator is used to call it.

Array Object Attributes

FF: Firefox, IE: Internet Explorer

Attribute
Description
FF
IE
 
Constructor
Returns a reference to the array function that creates this object.
1
4
 
Index
 
1
4
 
Input
 
1
4
 
Length
Sets or returns the number of elements in the array.
1
4
 
Prototype
Allows you to add attributes and methods to objects.
1
4
 

Array object Method

FF: Firefox, IE: Internet Explorer

Method
Description
FF
IE
 
Concat ()
Concatenate two or more arrays and return results.
1
4
 
Join ()
Put all elements of the array into a string. The elements are separated by the specified delimiter.
1
4
 
Pop ()
Delete and return the last element of the array
1
5.5
 
Push ()
Add one or more elements to the end of the array and return a new length.
1
5.5
 
Reverse ()
The order of elements in the array is reversed.
1
4
 
Shift ()
Delete and return the first element of the array
1
5.5
 
Slice ()
Returns the selected element from an existing array.
1
4
 
Sort ()
Sorts elements of an array.
1
4
 
Splice ()
Delete elements and add new elements to the array.
1
5.5
 
ToSource ()
Returns the source code of the object.
1
-
 
ToString ()
Converts an array to a string and returns the result.
1
4
 
ToLocaleString ()
Converts an array to a local array and returns the result.
1
4
 
Unshift ()
Add one or more elements to the beginning of the array and return a new length.
1
6
 
ValueOf ()
Returns the original value of the array object.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.