the murmurous sea

JS ES6: Array.from() 본문

#dev/개념정리

JS ES6: Array.from()

lunacer 2020. 6. 5. 18:11

1.  method 

2. creates a new, shallow-copied Array instance from an array-like or iterable object.

3. The length property of the from() method is 1.

4. In ES2015, the class syntax allows sub-classing of both built-in and user-defined classes.
   : As a result, static methods such as Array.from() are "inherited" by subclasses of Array, and create new instances of the subclass, not Array.

 

[Syntax]

Array.from(arrayLike [, mapFn [, thisArg]])
// has the same result as Array.from(obj).map(mapFn, thisArg)
// except that it does not create an intermediate array.
arrayLike   An array-like or iterable object to convert to an array.
    - array-like objects: objects with a length property and indexed elements.
    - iterable objects: objects such as Map and Set.
mapFn optional Map function to call on every element of the array.
Which allows you to execute a map() function on each element of the array being created.
thisArg optional Value to use as this when executing mapFn.

 

[Return Value]

A new Array instance.

 

[Examples]

1. Array from a String

2. Array from a Set

3. Array from a Map

4. Array from an Array-like object (arguments)

5. Using arrow functions and Array.from()

6. Sequence generator (range)

 


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

'#dev > 개념정리' 카테고리의 다른 글

JS: match() vs includes()  (0) 2020.06.24
JS: instance?  (0) 2020.06.10
Event: keydown, keypress, keyup  (0) 2020.06.05
JS ES6: Hoisting, Temporal dead zone  (0) 2020.06.03
JS: about Event  (0) 2020.06.03
Comments