The spread element ( this is not an operator ) only works with iterable objects (i.e. implement the @@iterator method). Array.from() also works with array-like objects (i.e., objects that have a length property and indexed elements) that are not iterable. See this example:
const arrayLikeObject = { 0: 'a', 1: 'b', length: 2 };
Also, if you just want to convert something to an array, I think it's better to use Array.from() , because it is more readable. Distribution elements are useful, for example, when you want to combine multiple arrays ( ['a', 'b', ...someArray, ...someOtherArray] ).
Michał Perłakowski Nov 11 '16 at 13:59 2016-11-11 13:59
source share