JavaScript Array Learning data Collection _ Basics

Source: Internet
Author: User
Tags array sort javascript array
In JavaScript, creating an array can use the new array, and the following syntax is correct:
Arrayobj = new Array () creates an array.

Arrayobj = new Array ([size]) creates an array and specifies the length, not the upper limit, but the length.

Arrayobj = new Array ([element0[, element1[, ...) [, ELEMENTN]]] Creates an array and assigns a value.

Arrayobj = [Element0, Element1, ..., ELEMENTN] Create an array and assign a shortened shorthand, note that the parentheses here do not indicate an omission.

To illustrate, although the second method creates an array that specifies the length, in all cases the array is longer, that is, even if you specify a length of 5, you can still store the elements outside the specified length, note: the length changes.

Does the new array (5) mean creating an array of length 5 or an array with an element value of 5? Create an array of length 5.

Are the array subscripts starting at 0 or starting at 1? Starting from 0, the upper bound of the array equals the length of the array-1.

What is the maximum value of an array subscript? 2 of 32 times to reduce 2, that is 4294967295, about 4 billion, enough.

Will the array be automatically rounded when it is marked as a decimal? No, a run-time error is ignored or occurs.

Do you support multidimensional arrays? Not supported! However, you can redefine each element of an array to an array to achieve the purpose of multidimensional arrays.

How do I access an array element? Using "[]", such as an array named arr, to access the first element, use Arr[0].

The JavaScript Array (JScript version 2) has 3 properties and 13 methods. Only length in 3 attributes is more important, but relatively simple, and the constructor and prototype attributes are common and not commonly used, so the array property is not introduced, and the array of 13 methods are introduced to facilitate memory.

POPs and Push:pop remove the last element and return the element value; push ([Item1 [item2]. [Itemn]]]) Adds one or more new elements to the end of the array and returns the new length of the array, and if you add an array, concatenate the elements of the array with commas before adding them.

Shift and Unshift: respectively correspond to pops and push, except that this is done at the beginning of the array. Note When you remove or add an element from the start position, the elements in the array are moved forward or moved back.

Slice and Splice:slice (start, [end]) return a portion of an array as an array, noting that the end-corresponding element is not included, if the end will copy all the elements after start; splice (Start, deletecount, [i tem1[, item2[, ... [, Itemn]]] Remove one or more elements of an array, if necessary, insert a new element in the position of the removed element, return the removed element as the form, and insert the first element of the array if the array is inserted.

Reverse and Sort:reverse () invert elements (top to bottom and last), and return array addresses; sort () array sorted and returns the address of the arrays.

Concat and Join:concat concatenate multiple arrays (or strings) into an array; join (separator) returns a string that joins each element value of the array, separated by separator.

toLocaleString, toString, valueof: Can be seen as a special use of join, not commonly used.

More basic information can be viewed: JS array

Fast cloning of JavaScript arrays (slice () function) and array sorting, ordering, and searching (sort () function

JavaScript deletes duplicates in an array (uniq)

Delete methods for elements in the JScript built-in object array

The JavaScript array uses the Call method rollup

JavaScript array sort function

Techniques for using objects and arrays in JavaScript

JavaScript cloning arrays is the easiest way

JavaScript creates the simplest code for an array

Performance comparison of JavaScript three array replication methods

More, you can find more relevant information by searching the "JavaScript array" above the page.

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.