An array of indexes, associative arrays, and static arrays in JavaScript, and dynamic arrays explain _javascript techniques

Source: Internet
Author: User
Tags in python

Array Categories:

1, from the array of subscript divided into index array, associative array

Copy Code code as follows:

/* Index array, that is, an array that is usually called/
var ary1 = [1,3,5,8];
Array elements by index, starting from 0 (of course some language implementations start at 1)
An index is actually an ordinal, an integer number
Alert (ary1[0]);
Alert (ary1[1]);
Alert (ary1[2]);
Alert (ary1[3]);

/* Associative array, an array that is accessed as subscript with a non-ordinal type called a dictionary in Python
var ary2 = {};
Access to non ordinal (number), here is the string
ary2["one"] = 1;
Ary2["two"] = 2;
ary2["THR"] = 3;
ary2["fou"] = 4;

2, from the storage of data into a static array, dynamic array

Copy Code code as follows:

static arrays in Java
The length of the array is fixed and cannot be changed, and array elements are indexed by index
Int[] Ary1 = {1,3,6,9};

Dynamic Arrays in Java
The ArrayList implementation in Java is based on array, which says that dynamic arrays are generalized, regardless of how they are implemented.
list<integer> Ary2 = new arraylist<integer> ();
Ary2.add (1);//You can add elements dynamically, and the length of the array changes as well.
Ary2.add (3);
Ary2.add (6);

Copy Code code as follows:

/* JS array belongs to the dynamic array * *
var ary = [];//defines an array with no length specified
Ary[0] = 1;//can dynamically add elements
Ary.push (3);
Ary.push (5);

Alert (Ary.join (","));//Output 1,3,5

JS Array is also an index array and dynamic array, because in essence it is a JS object, embodies the JS dynamic language characteristics. However, the indexed array of JS is not "continuously allocated" memory, so indexing does not bring high efficiency. An array in Java is a contiguous allocation of memory.

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.