JavaScript Basics-Using arrays

Source: Internet
Author: User

The array object provides a means to store and manipulate a set of other objects. Arrays can store numeric values, strings, or other JavaScript objects. There are several different ways to create JavaScript arrays. For example, the following statement wears the same 3 same version of a stop:

var arr = ["One", "one", "three"];

var arr2 = new Array ();

Arr2[0] = "one";

ARR2[1] = "both";

ARR2[2] = "three";

Arr3.push ("one");

Arr3.push ("both");

Arr3.push ("three");

The first method defines ARR and uses [] to set its contents in a statement. The second method creates the Arr2 object and then uses the direct index assignment to increase the entry. The third method creates the Arr3 object, and then pushes the entry onto the array using the best selection push () method of the extended array.

To determine the number of elements in an array, you can use the length property of the array object, as shown in the following example:

var numofitems = arr.length;

The array follows a zero-based index, which means that the first item is on index 0, and so on. For example, in the following code, the value of the variable first is Monday, and the last value of the variable will be Friday:

Var

Week = ["Mondy", "Tuesday", "Wednesday", "Thursday", "Friday"];

var first = w [0];

var last = week[week.length-1];

JavaScript Basics-Using arrays

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.