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)?
You could use Array.from
, which generates an array from an array like object.
this.products = Array.from(document.querySelectorAll('.product'));
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With