2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-30 17:34:11 +00:00
|
|
|
date: 2020-11-13
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 5ec66270-20b0-466e-85ea-dd7472a84880
|
|
|
|
title: Array.from()
|
|
|
|
---
|
|
|
|
|
|
|
|
# Syntax
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
const arr2 = Array.from(arguments);
|
|
|
|
```
|
|
|
|
|
|
|
|
If a value is [iterable](20201014092625-javascript_iterables) (as all
|
|
|
|
Array-like DOM data structure are by now), you can also use the
|
|
|
|
[spread](20201014094144-spread) operator (…) to convert it to an
|
|
|
|
[Array](20200826201029-arrays):
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
const arr1 = [...'abc'];
|
|
|
|
// ['a', 'b', 'c']
|
|
|
|
const arr2 = [...new Set().add('a').add('b')];
|
|
|
|
// ['a', 'b']
|
|
|
|
```
|