Array.from // usage of Array.of

// Array.from () // Array.of () usage
        // Array.from () usage
        // 1.Array from () array will be a class or an object, it is converted into a real array. The class must have an array length property
. 1   var List = {
 2              0: "Han" ,
 . 3              1: "Bai" ,
 . 4              2: "Another" ,
 . 5              3: "Zhao" ,
 . 6              length:. 4
 . 7          }
 . 8          var ARR = Array.from (List)
 . 9          the console.log (ARR); // output: [ "Han", "Bai", "Liang", "Zhao"]
// can convert 2.Array.from () in the form of a string array
1 var str = 'chenbin'
2         var arr1 = Array.from(str)
3         console.log(arr1);// 输出结果: ["c", "h", "e", "n", "b", "i", "n"]
        // 3.Array.from () can be passed a second parameter, map (similar to the array) method (Array.from (obj, mapFn, thisArg) format corresponds Array.from (obj) .map (mapFn , thisArg)), each processing element, the processing element of the array back
1  var arr3 = [1,2,3,4,5]
2         var newarr = new Set(arr3)
3         console.log(Array.from(newarr,item=>item+1));//输出结果: [2, 3, 4, 5, 6]

 

 

// Array.of()
        // Create a new array variable number of parameters, regardless of the type and number of parameters
        Difference // Array.of () constructor and Array: an integer that the processing parameters
        // Array (7) represents create an empty array of length 7
        // Array.of (7) represents the creation of an array which has an array of individual elements 7, its length is 1
. 1   var of arr1 the Array = (10 )
 2          the console.log (of arr1); // [empty × 10] is a length of array 10 is empty 
. 3          var arr2 is = Array.of (10 )
 . 4          the console.log (arr2 is); / / [10] is an array with a single element 10, its length is 1 
. 5         

 

Guess you like

Origin www.cnblogs.com/1825224252qq/p/11783260.html