[英]Javascript HTMLCollection to array using slice. Why does it work?
Haii so I've recently used converting HTMLCollection
to array in order to use the filter
method and that by doing Array.prototype.slice.call(htmlcollection).filter(...);
Haii,所以我最近使用将HTMLCollection
转换为数组以使用filter
方法,并且通过执行Array.prototype.slice.call(htmlcollection).filter(...);
from a stackoverflow answer but I can't figure out 2 things:来自stackoverflow的答案,但我无法弄清楚两件事:
Array.prototype.slice(htmlcollection).filter(...);
won't work行不通HTMLCollection
use an array method HTMLCollection
如何使用数组方法Finally I'd like to create this behavior in my own classes so I can call Array.prototype.slice.call(new MyClass()).filter(...);
最后我想在我自己的类中创建这种行为,这样我就可以调用Array.prototype.slice.call(new MyClass()).filter(...);
Thanks in advance for your generous contribution and time预先感谢您的慷慨贡献和时间
You can use the Array.from()
method您可以使用Array.from()
方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.