Reputation: 13304
In another question posted this was there:
var a = {};
a.products = [...document.querySelectorAll('.product')];
console.log(a.products);
<div class="product"> </div>
Edge will fail with the following error:
function expected
However this is working:
var params = ['hello', '', 7];
var other = [ 1, 2, ...params];
console.log(params);
console.log(other);
Why isn't the top one working on Edge (it does on Chrome)?
Upvotes: 12
Views: 2663
Reputation: 388
Update to 2020, Edge is now using Chrome v8 internally. Ask the user to download latest version of Edge. No need to take care of this specific scenario in old Edge.
Upvotes: 0
Reputation: 13304
Well it looks like Bergi and Felix are on the right track: in this document on MDN they talk about iterators.
Some built-in constructs, such as the spread operator, use the same iteration protocol under the hood:
So where Array does have entries()
a nodelist
in Edge doesn't and does not support iteration.
Nina's answer is the goto one!
Upvotes: 1
Reputation: 386806
You could use Array.from
, which generates an array from an array like object.
this.products = Array.from(document.querySelectorAll('.product'));
Upvotes: 8