Summary of JS array method

Source: Internet
Author: User

Summary of common methods for arrays

  does not change the original array 1, array.length;                      //Get array length 2, array.join ();                        //The array is stitched together with the string passed in, returning the stitched string, with the default "," to splice. 3, Array.concat ();                    //can add multiple elements passed in to the end of the array, or Arrays 4, Array.slice ()   &NBSP ;                    //for copying part of the array below, the incoming two parameters specify the start and end positions respectively, and negative numbers are reversed. 5, array.tostring ()                  //equivalent to Array.join (', '); 6, Array.every ( function (Value,index,array)) {});    //For each element in the array for conditional detection, all satisfied returns True, otherwise false;7, array.some (function (Value,index,array)) {}) are returned;    //is used for conditional detection of each element in an array, returns true if one satisfies, otherwise returns FALSE;8, Array.filter (function (Value,index,array)) {});    //For filtering the array elements that satisfy the condition and returning them to the new array; 9, Array.map (function (Value,index,array)) {});    //To modify each element in an array and return a new array of its constituent 10, ARRAy.foreach (function (Value,index,array)) {});              //for each element operation in an array, no return value 11, array.reduce (function (Prev,cur,index,array) { }, [init]),  //all items of the iterated algebraic group, and then constructs a final returned value. The first parameter is the handler function, and the arguments are the previous value, the current value, the index, and the array.  //The Second optional parameter is the initial value, and if omitted, the first element of the array is  //in an empty array, and there is no initial value, which results in an error; the  //array has only one value and no initial value, or an empty array but has an initial value, it returns that value.  //Example:  var values = [1,2,3,4,5]; var sum = values.reduce (function (prev, cur, index, values) {        return prev + cur; });  12, Array.reduceright (function (Prev,cur,index,array) {}, [init]);  Works the same as the reduce method, but starts at the right end.  13, Array.indexof (Index,[start]);        //To find the specified array element from the start position (optional), return its index position, and return 114, Array.lastindexof (Index,[start]) if not found;    //similar to the IndexOf method, but it is looked up from the right end.   Change the original array 1, Array.reverse ();      //reverse the elements in an array, returning an array of 2, Array.Sort () in reverse order;          //arrange array elements, default an alphabetical list, and uppercase letters in front of lowercase letters, return the array   Expand: Arrange the numbers  array.sort ( function (A, b) {&NBsp                                 return a- b;                           });  case insensitive: Arra Y.sort (function (A, b) {                            & nbsp      var m = a.tolowercase (),                      nbsp                   n = b.tolowercase ();          &NBS P                        if (M > N) {      &NBS P                                  retu RN 1                                   Else {                              &N Bsp          return-1;                      & nbsp            }                      &N Bsp    });  3, Array.splice ()          //used to insert or delete elements in an array, the first parameter specifies the position of the element to be deleted, The second parameter specifies the number of deleted elements,                              &N Bsp      //If you remove all subsequent elements, the third and subsequent elements are added to the array at the specified position. This function returns                                 &NBS P    //An array of deleted elements, and returns an empty array if no elements are removed.  4, Array.push ()        //adds one or more elements to the end of the array, and returns the length of the array. 5, Array.pop ()        //delete an element at the end of the array, returning the deleted element 6, Array.unshift()    //Add one or more elements to the head of the array and return the array length. 7, Array.shift ()      //delete an element of the array header, returning the deleted element

JS Array Method Summary

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.