There are two new methods of Array in ES6, Array.of() and Array.from(). The difference usage of them are mentioned in this page.
However, I am confused with the usage of Array.of in this line
// usage of Array.of
console.log(
Array.of( "things", "that", "aren't", "currently", "an", "array" )
); // ["things", "that", "aren't", "currently", "an", "array"]
What if we do it as below,
console.log(
[ "things", "that", "aren't", "currently", "an", "array" ]
); // ["things", "that", "aren't", "currently", "an", "array"]
The same result we can get as console.log(Array.of(...)). Any advantage of using Array.of here?
Also confused with the usage of Array.from in this line
var divs = document.querySelectorAll("div");
console.log(
Array.from( divs )
);
What if there is no Array.from in the above codes.
var arr = [1, 2, 3];
console.log(Array.from(arr)); // [1, 2, 3]
console.log(arr); // [1, 2, 3]
Any advantage of using Array.from here?
Array.ofover an array literal. There is an advantage of usingArray.ofovernew Array.Array.fromon an array. There is an advantage of usingArray.fromon an array-like object such as aNodeList.