Array Common APIs

Source: Internet
Author: User

Push: Trailing add
Grammar:
Arr.push ();
Return value: The length of the array after the data has been added
Change Element Group

    var arr = [10,20,30,40];    var newArr = Arr.push (50);    Console.log (Arr,newarr);    Unshift: Header Add Syntax: Arr.unshift ();    Return value: The length of the array after adding the data will change the original array var arr = [10,20,30,40];    var newArr = Arr.unshift (50);            Console.log (Arr,newarr);    Pop: Trailing delete syntax: Arr.pop () Delete is a return value that does not need to pass parameters: the deleted data will change the original array var arr = [10,20,30,40];    var newArr = Arr.pop ();    Console.log (Arr,newarr);    Shift: Header deletion syntax: arr.shift () Delete is a return value that does not need to pass parameters: the deleted data will change the original array var arr = [10,20,30,40];    var newArr = Arr.shift (10);    Console.log (Arr,newarr);    Reverse: Inversion Syntax: Arr.reverse ();    Return value: Inverse of the array will change the original array var arr = [10,20,30,40];    var newArr = Arr.reverse ();    Console.log (Arr,newarr);        Sort (): Sorting---> Interview basically all the grammar: Arr.sort ();        1, Arr.sort ();         If the data in the array is less than 10, it can be sorted as normal var arr = [9,4,8,2,7,3];         var newArr = Arr.sort ();         Console.log (Arr,newarr); When a parameter is not passed in sort, it is sorted by ASCII code 2, sortPass parameter Arr.sort (function (A, b) {return a-A;             }) var arr = [9,14,8,21,7,31];             var newArr = Arr.sort (function (A, b) {return b-a;        }) Console.log (NEWARR);        3. mixed row var arr = [10,20,30,40,50,60,70];        var newArr = Arr.sort (function () {return 0.5-math.random (); }) Console.log (arr) */concat (): Array of spliced arrays. Concat (array) The return value is a concatenation after the new array does not change the original array var arr = [10,20,30];var arr1 = [40,50,60];va R NEWARR = Arr.concat (arr1); Console.log (Arr,arr1,newarr); join: Converts an array to a string var arr = [10,20,30];var str = Arr.join ("!"); Console.log (ARR,STR); The return value is a converted string that can pass characters without altering the original array split: convert string to array var str = "another parting"; var arr = Str.split (""); Console.log (Str,arr); ToString (): Converts an array to a string var arr = [10,20,30,40,50];var str = arr.tostring ();//Check toString usage//tostring () The return value of the function is of type string. Returns the string form of the current object.    Console.log (ARR,STR); slice: Array intercept delete start: Intercept start position end: Intercept end position (optional)//left closed right open var arr = [10,20,30,40,50]; VarNEWARR = Arr.slice (2,5);    Console.log (Arr,newarr); The original array did not change splice: array interception can be inserted to replace delete start: Add or remove the starting position subscript the second value: if 0 is the case of adding a non-0 case is to delete the number of deleted or added third value: The number to be added or removed (optional); If the second parameter is not 0 The case is replaced, the return value is replaced by the data, the original array is changed after the data will change the original array var arr = [10,20,30,40,50,60,70];var newArr = Arr.splice (1,0,5); Co Nsole.log (Newarr,arr)

Array Common APIs

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.