Common Array API ForEach every some sort map filter slice indexOf

Source: Internet
Author: User

vararr = [n/a];//[] is the new Array (All-in-one) syntax sugar (shorthand) varobj = {' name ': 2, ' Age ': 3};//{} is a shorthand for new Object () //var obj2 = new Object (); //obj2.name=2; //obj2.age=3; //ForEach facilitates all elements Arr.foreach (function(item,index) {//iterate over all elements of an arrayConsole.log (item)//1 2 3  })//Every determine if all elements meet all conditions varPD = Arr.every (function(item,index) {//used to determine that all array elements satisfy a condition        if(item<4){            return true; }}) Console.log (PD)//true//Some determine if at least one element meets this conditionvarPD2 = Arr.some (function(item,index) {//used to determine that all array elements satisfy a condition     if(item<2){       return true; }}) Console.log (PD2)//true//Sort from small to largevarArrsort =NewArray (1,4,5,7,9,3);varpx = Arrsort.sort (function(A, b) {//from small to large       returnAb; //from big to small       //return b-a;}) Console.log (px)//[1, 3, 4, 5, 7, 9]//Map to re-assemble elements to generate a new arrayvarCZ = Arr.map (function(item,index) {return' <b> ' +item+ ' </b> '}) Console.log (CZ)//["<b>1</b>", "<b>2</b>", "<b>3</b>"]//filter filters elements that match the criteriavarfi = Arr.filter (function(item,index) {//filter out non-qualifying array elements    if(item>=2){        return true; }}) Console.log (FI)//[2, 3]
//Slice () intercepts some elements of an array var demoarr = [1,2,3,4,5,6,7,8,9,10]console.log (demoarr.slice (///// The first parameter starts at which position The following table is the second parameter starting from 0, which  is from the No. 0 small label
//indexof Remove duplicate elements in the array and sort var cfarr = [' B ', ' G ', ' a ', ' C ', ' e ', ' f ', ' d ', ' a ', ' G ', ' B ']; var zzarr = [];    for (var i=0;i<cfarr.length;i++) {      if(Zzarr.indexof (cfarr[i]) ==-1) {        Zzarr.push (Cfarr[i])      }  

Common Array API ForEach every some sort map filter slice indexOf

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.