Arrays in JavaScript

Source: Internet
Author: User

Two ways to create an array

var a=[]

var a=new Array ();

Traversal of an array

vara=[1,2,3,4,5]; for(Let i=0, len=a.length;i<len;i++){    //Three Choice one    if(!a[i])Continue;//skipping null,undefinded and non-existent elements    if(a[i]===undefined)Continue;//skipping undefined and non-existent elements    if(! (A[i]inchA))Continue;//skipping elements that do not exist}

Methods of arrays

Array.join ()//merging arrays into stringsArray.reverse ()//arrange the elements in the array in reverse orderArray.Sort ()//sorting an array elementArray.concat ()//Create returns a new array, including the parameters in the concatArray.slice ( from, to)//intercepts an array without modifying the original arrayArray.splice (Index,len,newargs)//inserting or deleting an elementArray.push ()//add an element at the endArray.pop ()//Delete an element at the end of theArray.unshift ()//add an element at the beginning to insert multiple elements at onceArray.shift ()//Delete an element at the beginningArray.tostring ()//The tostring method of the prototype object is overridden, like a join without parameters//ECMA5ForEach (function (item) {})//Looping throughMap (function (item) {return})//each element of the call array is passed to a function and returns a new arrayFilter (function (item) {return true/fasle})//filters each element in the array and returns a new array (true)Every (function (item) {})//returns Ture () when all elements in an array call a function and both return TrueSome (function (item) {})//at least one return true returns trueReduce (function (x, y) {},begin)//two parameters, the first parameter is the function that performs the simplification operation, the second parameter is the starting value, the second parameter is not empty, is the first parameter of the simplification function, the second parameter of the simplification function is the first element of the array, the return value of the degenerate function is the first parameter of the next execution function. When the second argument is empty, the parameter of the degenerate function is the first element of the array and the second elementReduceright ()//ditto, but he went from the end to the executionIndexOf ()//searches for an element with the given value in the arrayLastindexOf ()//Reverse Search

Arrays in JavaScript

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.