JS indexed arrays, associative arrays and static arrays, dynamic arrays

Source: Internet
Author: User

1 JS indexed arrays, associative arrays and static arrays, dynamic arrays2 3 Array Classification:4 51, from the subscript of the array into an indexed array, an associative array6 7 varAry1 = [1,3,5,8];8 //to fetch array elements by index, starting from 0 (of course some languages are implemented starting from 1)9 //an index is actually an ordinal, an integer numberTenAlert (ary1[0]); OneAlert (ary1[1]); AAlert (ary1[2]); -Alert (ary1[3]); -  the  - varAry2 = {}; - //when accessed, as a non-ordinal (number), here is the string -ary2["one"] = 1; +ary2["2"; -ary2["THR"] = 3; +ary2["fou"] = 4; A  at2, from the storage of data into static arrays, dynamic arrays -  -Int[] Ary1 = {1,3,6,9};//after defining the length of the array fixed cannot be changed, indexed by the array element List Ary2 = new ArrayList (); Ary2.add (1);//can add elements dynamically, the length of the array varies ary2.add (3); Ary2.add (6);  -  -   -  in varary = [];//defines an array that does not specify a length -Ary[0] = 1;//You can add elements dynamically toAry.push (3); +Ary.push (5); -  theAlert (Ary.join (","));//Output 1,3,5 *  $ the array of JS is both an indexed array and a dynamic array, because it is essentially a JS object that embodies the JS Dynamic language feature. However, the indexed array of JS is not "contiguous allocation" of memory, so indexing does not bring high efficiency. The array in Java is a contiguous allocation of memory. Panax Notoginseng  - Array Object Sort Method the Description: + returns an Array object for which an element has been sorted. A  the Syntax: + sort () sorts the character nginx by default. - Arrayobj.sort (sortfunction) $If the request results are 10, 16, 120 to sort the number size, you should use the following program: $  -   - function(x, y) is a function to implement the sorting function, the above method is the implementation of ascending, if you want to implement descending, you can change the return result:returnparseint (Y)-parseint (x); theOf course, if you want to implement string sorting, you can use A.sort (param), that is, sort (param) to sort the string by default, the parameter is a function, if omitted, then the element will follow the ASCII The character sequence is sorted in ascending order. Of course, you can also implement a long data sort, change the parseint to Parselong.

JS indexed arrays, associative arrays and static arrays, dynamic 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.