As javascript arrays are widely used and more friends are using them, students have compiled some js data learning materials for everyone. After reading them, they should have an understanding of arrays. In JavaScript, you can use new Array to create an Array. The following syntaxes are correct:
ArrayObj = new Array () to create an Array.
ArrayObj = new Array ([size]) Create an Array and specify the length. Note that the length is not the upper limit.
ArrayObj = new Array ([element0 [, element1 [,... [, elementN]) to create an Array and assign values.
ArrayObj = [element0, element1,..., elementN.
It should be noted that, although the second method creates an array with a specified length, the array actually gets longer in all cases, that is, even if the length is 5, you can still store elements outside the specified length. Note: The length will change accordingly.
Does new Array (5) Create an Array with a length of 5 or an Array with an element value of 5? Create an array of 5 characters.
Is the array subscript starting from 0 or starting from 1? Starting from 0, so the upper limit of the array is equal to the length of the array-1.
What is the maximum value of the underlying mark of the array? The power of 2 is reduced by 2 to the power of 32, that is, 4294967295, about 4 billion. That's enough.
Will the array be automatically rounded up when the subscript is decimal? No, it will ignore or cause a runtime error.
Is multidimensional array supported? Not Supported! However, each element of the array can be further defined as an array to achieve the goal of multi-dimensional arrays.
How to access array elements? Use "[]". For example, if the array is named arr and you want to access the first element, use arr [0].
JavaScript Array (JScript version 2) has three attributes and 13 methods. Only length is important among the three attributes, but it is relatively simple. In addition, constructor and prototype attributes are common and not commonly used, so we will not introduce the Array attribute, the introduction of 13 method groups in Array makes it easier to remember.
Pop and push: pop removes the last element and returns the value of this element. push ([item1 [item2 [... [itemN]) adds one or more new elements to the end of the array, and returns the new length of the array, if an array is added, use a comma to connect the elements of the array and then add it.
Shift and unshift: respectively correspond to pop and push, but this is done at the beginning of the array. Note that when elements are removed or added from the starting position, the elements in the array are moved forward or backward.
Slice and splice: slice (start, [end]) returns a part of the array in the form of an array. Note that the end element is not included. If the end is omitted, all the elements after the start are copied; splice (start, deleteCount, [item1 [, item2 [,... [, itemN]) removes one or more elements from the array. If necessary, insert new elements to the position of the removed elements. Return the removed elements in the array format, if an array is inserted, only the first element of the array is inserted.
Reverse and sort: reverse () reverses the elements (first to last and last to the first) and returns the array address; sort () sorts the array and returns the array address.
Concat and join: concat concatenates multiple arrays (or strings) into an array. join returns a string that concatenates each element value of the array, separated by separator.
ToLocaleString, toString, valueOf: can be considered as a special use of join, not commonly used.
For more basic information, see js array.
The slice () function) and the sort, out-of-order, and search (sort () function of the JavaScript Array
Javascript deletes repeated items in the array (uniq)
How to delete elements in the Array of the built-in object in JScript
Javascript array summary using call Methods
Javascript array sorting Function
How to Apply objects and arrays in javascript
The easiest way to clone arrays using JavaScript
The simplest code for creating arrays in javascript
Performance Comparison of Three array replication methods in javascript
For more information, you can search for "javascript array" on the page.
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.