Part of an array of methods:
<! DOCTYPE HTML > < HTML lang = "EN" > < head > < Meta charset = "UTF-. 8" > < title > the Title </ title > </ head > < body > < P > Mu class network </ P > < the p- > Miao taste the classroom </ the p- > < the p- > Ashoka classroom </ the p- > <script> //Array.of () will be combined into a passed parameter array the let ARR = Array.of ( . 1 , 2 , . 3 , . 4 , . 5 , . 6 ); the console.log (ARR) // [1,2,3,4 , 5,6] the let of arr1 = Array.of (); the console.log (of arr1) // [] // Array.from a set of arrays may be transformed into a map of an array of the let P = document.querySelectorAll ( ' P ' ); the let Parr = Array.from (P); pArr.forEach ( function (Item) { the console.log (item.innerHTML) }) the console.log (Array.from ([ . 1 , . 3 , . 5 ], function (Item) { return Item * 2 ; })) // [2,6,10] first parameter array is a function of the second parameter mapping array </ Script > </ body > </ HTML >
// Fill () the elements in an array subscript end alternative first parameter the second parameter is replaced replacement alternative starting index third parameter console.log ([ 'a', ' b ', 5,' Hello ', 9] .fill (' replacement ', l, 3)) // [ "A", "replace", "replace", "Hello", 9]
// Get the first value in the array satisfies the condition of the console.log ([1,2,3,4,5,6] .find ( function (Item) { return Item>. 3 })); // Get array the first index value satisfying the condition of the console.log ([1,2,3,4,5,6] .findIndex ( function (Item) { return Item>. 3 })); // determines whether there is an array parameters passed the console.log ([1,2, NaN3] .includes (. 1 )); the console.log ([ 1,2, NaN3] .includes (NaN3));
Traversing the details of the array:
for(let index of ['1','c','ks'].keys()){ console.log('keys',index); } //values需要用babel-polyfill for(let value of ['1','c','ks'].values()){ console.log('values',value); } for(let [index,value] of ['1','c','ks'].entries()){ console.log('values',index,value); }
Matching rules:
const ARR = [ 'A', 'B', [ 'C', 'D', [ 'E', 'F', 'G' ]]]; the let [,, [,, [,, Q]] ] = ARR; Alert (Q); // pop g
Exchange variables:
A = 20 is the let ; the let B = 10 ; [A, B] = [B, A]; // result a = 10, b = 20 swaps two variables
Extended operator:
of arr1 = const [l, 2,3 ]; const arr2 is = [ 'A', 'B' ]; const ARR3 = [ 'AAA', 456 ]; const arr4 = [... of arr1, ... arr2 is ,. ..arr3]; // arr4 => the arr1, arr2, arr3 combined into an array = arr4 [l, 2,3, 'a', 'B', 'AAA', 456] const ARR = [1,2 , 3,4- ]; const [a, B, C ...] = ARR; // remaining unmatched to merge into a value assigned to the array cc = [3,4]
Receiving a plurality of function return value:
function getNum () { return [ "Hello" , { name: "Bob" , Age: 16 , Sex: "M" }, ]; } const [First, SECOND, THIRD] = getNum (); / * Results: girst => "Hello", second => {name: " Bob", age: 16, sex: " M"}, THIRD => 123 * /