Several ways that JavaScript creates arrays

Source: Internet
Author: User
Tags javascript array

1. Simply create a JavaScript array:

Vararr=newarray ();

Important: Create an Array object with the New keyword array (), the array () object is a local class that can be created with the new object using the

2. Specify the array size while creating the JavaScript array:

Vararr=newarray (10);//This creates an array with an initial size of 10

Note: When using the array size operation to initialize the size, the array will automatically become large and will not have an error like the C language. Dynamic growth is a property of the JS array. In addition, JS supports a maximum array length of 4294967295

3. Direct initialization:

Vararr=newarray ("Paramecium", "Love", "fluffy");//This is directly initialized with an array or vararr=["Paramecium", "Love", "fluffy"];//parentheses can also declare an array object, of course, like the C language, You can also define 2-dimensional 3-and multidimensional arrays, which are not discussed here.

2. Create Array Direct volume

var a=[1,2,3,4,5];

var a=["string", "id", "it", true,3];

The direct amount of an array can also contain direct amounts of objects and other array direct quantities

Several ways that JavaScript creates arrays

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.