Introduction to JavaScript Minimalist Tutorial (iii): Array _javascript Tips

Source: Internet
Author: User

Reading this article requires programming experience in other languages.

An array in JavaScript is an object (rather than a non-linear allocated memory).

To create an array through array literal:

Copy Code code as follows:

var empty = [];
var numbers = [
' Zero ', ' one ', ' two ', ' three ', ' four ',
' Five ', ' six ', ' seven ', ' eight ', ' nine '
];
EMPTY[1]//undefined
NUMBERS[1]//' one '
Empty.length//0
Numbers.length//10

The array has a property length (and the object does not) to represent the lengths of the array. The value of length is the maximum integer property name plus 1 for the array:

Copy Code code as follows:

var myarray = [];
Myarray.length; 0
MYARRAY[1000000] = true;
Myarray.length; 1000001

We can modify the length directly:

Length change will not cause more space to be allocated
Length is changed to small, all attributes with subscript greater than or equal to length are deleted
Because arrays are also objects, you can use Delete to remove elements from an array:

Copy Code code as follows:

Delete Number[2];
NUMBER[2] = = undefined;

This removes the element from the array leaving a void.

JavaScript provides an array of methods that are placed in Array.prototype (not described in detail here).

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.