Javascript array object

Source: Internet
Author: User
Tags javascript array

An array object uses a separate variable name to store a series of values.

Instance
Create an array
Create an array, assign values to it, and then output these values.
For... in statement
Use the for... in Declaration to cyclically output the elements in the array.
Merge two Arrays-Concat ()
How to Use the Concat () method to merge two arrays.
Using array elements to form a string-join ()
How to Use the join () method to make all elements of an array a string.
Text array-sort ()
How to Use the sort () method to sort arrays literally.
Number array-sort ()
How to Use the sort () method to sort arrays from numeric values.
Complete array Object Reference Manual

We provide Javascript array Object Reference Manual, which includes all attributes and methods that can be used for array objects.

This Manual contains a detailed description of each attribute and method and related examples.

Define an array

An array object is used to store a series of values in a separate variable name.

We use the keyword new to create an array object. The followingCodeDefines an array object named myarray:

 
VaR myarray = new array ()

There are two ways to assign values to an array (you can add any number of values, just as you can define any number of variables you need ).

1:
 
VaR mycars =New array ()Mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW"

You can also use an integer independent variable to control the array capacity:

VaR mycars =New array (3)Mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW"
2:
VaR mycars =New array ("Saab", "Volvo", "BMW ")

Note:If you need to specify a value or logical value in the array, the variable type should be a numeric or Boolean variable, rather than a character variable.

Access Array

By specifying the array name and index number, you can access a specific element.

The following is the code line:

Document. Write (mycars [0])

The output is as follows:

Saab
Modify values in an existing array

To modify the values in an existing array, you only need to add a new value to the specified label:

Mycars [0] = "Opel ";

Now, the above Code is as follows:

Document. Write (mycars [0]);

Output:

Opel

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.