I found the Spread operator can be used with arguments
:
function foo() {
[...arr] = arguments;
console.log(arr, Array.isArray(arr));
}
foo(1, 3, 5);
// note that we could also use function foo(...args) { } to begin with
But not with an object that is array-like (it would throw an error TypeError: undefined is not a function
):
let obj = { 0: "abc", 1: 3.14, length: 2 };
[...arr] = obj;
console.log(arr, Array.isArray(arr));
So can the Spread operator be used with array-like objects?
As a side note, the following could both make an array:
let obj = { 0: "abc", 1: 3.14, length: 2 };
let arr = Array.prototype.slice.call(obj);
console.log(arr, Array.isArray(arr));
let arr2 = Array.from(obj);
console.log(arr2, Array.isArray(arr2));