简体   繁体   English

Javascript HTMLCollection 使用切片进行数组。 为什么它有效?

[英]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的答案,但我无法弄清楚两件事:

  1. Array.prototype.slice(htmlcollection).filter(...); won't work行不通
  2. How can a 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()方法

Reference here 参考这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么Array()。切片没有“新”工作? - Why does Array().slice without “new” work? .pop()/ slice。()在数组上不起作用。 需要计数工作-Javascript - .pop() / slice.() on arrays not working. Need count working - Javascript 上传最后一个文件切片时代码失败。 (javascript,html 5) - Code fails when uploading last file slice. (javascript, html 5) JavaScript本机.remove()在HTMLCollection上不起作用。 Javascript Bug? - Javascript native .remove() does not work on HTMLCollection. Javascript Bug? 为什么 addEventListener 属性在动态 HTMLcollection object 上不起作用? - Why does the addEventListener property does not work on a dynamic HTMLcollection object? Array.from() with HTMLcollection 在 Chrome 浏览器中似乎不起作用 - Array.from() with HTMLcollection does not seem to work in Chrome browser 为什么数组切片将javascript参数转换为数组 - why does array slice convert javascript arguments to array 鉴于“arguments”不是一个真正的数组,为什么Array.prototype.slice.call(arguments)工作,但是Array.prototype.slice.call(someobject)不起作用? - Given that “arguments” is not a true array, why does Array.prototype.slice.call(arguments) work, but Array.prototype.slice.call(someobject) not work? Javascript-使用原型将HTMLCollection字符串化 - Javascript - HTMLCollection to string using prototype 为什么 forEach 方法不适用于 HTMLCollection - Why forEach method doesn't work on HTMLCollection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM