[JavaScript] JavaScript learns 25 Javascript array objects.

Source: Internet
Author: User
Tags javascript array
Document directory
  • 1:
  • 2:

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 a reference manual for Javascript array objects, including all the 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 following code defines 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.