ES6 syntax (array extension)

Source: Internet
Author: User

{let arr= Array.of (3, 4, 7, 9, 11); Console.log (' arr ', arr);//[3,4,7,9,11]Let empty =Array.of (); Console.log (empty); //[]}//ES6 adds the FROM function to array to convert other objects into arrays. //of course, other objects are also required and not all, and two objects can be converted to an array. //1. Objects with iterator interfaces are deployed, such as: Set,map,array. //2. Class Array object, what is called the class array object, is an object must have the Length property, no length, the empty array is turned out. {    //Converting ArraysLet P = Document.queryselectorall (' P '); Let PArr=Array.from (P); Parr.foreach (function(item) {Console.log (item.textcontent);//es6, hehe Hey, happy move.    }); //MapConsole.log (Array.from ([1, 3, 5],function(item) {returnItem * 2        })) //2,6,10}//array padding{Console.log (' Fill-7 ', [1, ' A ', Undefined].fill (7))//7,7,7Console.log (' Fll,pos ', [' A ', ' B ', ' C '].fill (' 7 ', 1, 3));//a 7 7 (1,3) represents the starting position, and 7 is the fill content}//Traverse related{    //Take position     for(Let index of[' 1 ', ' C ', ' KS '].keys ()) {Console.log (' Keys ', index);//0 1 2    }    //Take value     for(Let value of[' 1 ', ' C ', ' KS '].values ()) {Console.log (' Values ', value);//1 C KS (There is compatibility problem, need to introduce import ' Babel-polyfill ')    }    //take position and value     for(Let [index, value] of[' 1 ', ' C ', ' KS '].entries ()) {Console.log (' Values ', index, value);//0 1 2,1 C ks    }}//assigns a member to another place within the current array's inner array{Console.log ([1, 2, 3, 4, 5].copywithin (0, 3, 4));//4,2,3,4,5 (Start position 0, starting from the third reading, the cutoff position is 4, i.e. 5 numbers)Console.log ([1, 2, 3, 4, 5].copywithin (1, 3, 4))//1,4,3,4,5Console.log ([1, 2, 3, 4, 5].copywithin (0,-2,-1))//4,2,3,4,5}//Find{Console.log ([1, 2, 3, 4, 5, 6].find (function(item) {returnItem > 3//4 Only find the first value, not the next one.    })); Console.log ([1, 2, 3, 4, 5, 6].findindex (function(item) {returnItem > 3//3 was looking for the subscript.    }));}//NaN{Console.log (' Number ', [1,2,nan].includes (1)];//true if this value is includedConsole.log (' number ', [1,2,nan].includes (NaN));//true}

ES6 syntax (array extension)

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.