Array object in JavaScript

Source: Internet
Author: User

1. Create an Array object
Syntax for creating an Array object
Var Array name = new Array ();
After defining the array, you need to add elements to the array. The format is as follows:
Array name [ <Subscript> ] = Value;


2. Array Object Attributes
The Array object only provides four attributes.
Index: Specifies the position where the character matches the string, or if-1 is not found.
Input: Specifies the original string that matches the regular expression.
Length: returns the length of the array, that is, the number of elements in the array. This attribute can be used to easily traverse the array.
Prototype: add the newly defined attribute or method to the Array object. Then, the instance of this object can call this attribute or method.


3. Array object Method
Concat (): For object link reference, copy the value of a character or string
Join (): all elements separated by the specified separator
Pop (): removes the last element from the array and returns the element. If the array is empty, underfined is returned.
Push (): append new elements in the order they appear.
Shift (): remove the first element from the array and return it.
Unshift (): inserts these elements into the beginning of an array so that they are sorted in order in the parameter table.
Reverse (): sorts array elements in the opposite direction.
Sort (): returns the sorted Array object. By default, elements are sorted in ascending order of ASCII characters.
Splice (): removes the specified number of elements starting from the start position and inserts new elements to modify the array. The returned value is a new Array object consisting of the removed elements.
TolocalString (): returns a value in the form of a string value, which is suitable for the region settings in the current environment
ToString (): returns the string representing the object.
ValueOf (): returns the original value of the specified object.

Related Article

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.