I don't know Javascrip "array" There are so many things ....

Source: Internet
Author: User

Some time ago in the frequent use of arrays, but have never known JavaScript arrays and so many things, collected a look at:

First: The array is the special form of the object , and then see what it means ...
Push () adds at the end of one or more
Unshift () Inserts an element in the header of the array
Delete Deletes an array element, but does not change the length of the array (instead, it becomes a sparse array)
Pop () and shift () delete
Skips undefind elements such as if (a[i]===undefinend) continue when iterating through an array;
Use foreach () to iterate through an array, for example: Var data=[1,2,3,4,5]; var sum=0;
Data.foreach (function (x) {sum+=x*x});
Sum

Multidimensional array: ....
Array method:
Join () converts all elements in the array to strings and joins together note: If you do not specify a delimiter, the default
Use commas!
Reverse () Reverses the elements in the array
Sort () sorted in alphabetical order without parameters
Concat () Creates and returns a new array
Slice () returns the specified sub-array
Splice () Common method for inserting or deleting elements in an array (the original array is modified)
Push (), adding one or more elements at the end of the array
Pop () vice versa is to delete the last element of the array, reduce the length of the array, and return the value it deleted
Note: Both push and pop are modified and replaced with the original array
Unshift () and Shift () are inserted or deleted in the head of the array exactly the opposite of the two above
Array already has ToString () method
Iterate through the array: ForEach ("array element", "element Index", "Array Itself") method.
The map () method passes each element of the call array to the specified function. and returns an array
Example: a=[1,2,3]; B=a.map (function (x) {return x*x}) The value of//b is [1,4,9]
Filter () similar to map ();
Every () and some () For example: a=[1,2,3,4]; A.every (function (x) {return x<10})//Return
Back to true; some is similar to "presence"
Reduce () and reduceright () are called "injected" or "collapsed"--(simplifying functions)
IndexOf () and LastIndexOf () if not found, return-1
Distinguish whether it is an array: for example Array.isarray ([])//=> True

CharAt () accesses a single character: for example: Var s=test; S.charat (0) s[1]//=> "E"

----above is my own collection, may not complete, welcome to add!

I don't know Javascrip "array" There are so many things ....

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.