There are these two ES6-methods of creating an array from an array-like or iterable object:
- Array.from():
let arr = Array.from(Object);
- Spread syntax:
let arr = [...Object];
Here are both in action doing exactly the same:
let string = 'foobar';
console.log( [...string] );
console.log( Array.from(string) );
What is the difference between the two and which one should I use preferably to convert a HTMLCollection to an array?