JavaScript替代“每个”循环 [英] JavaScript alternative to "for each" loop
本文介绍了JavaScript替代“每个”循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据上的MDN页面...在循环中,此构造已被弃用。有没有一个可以做同样的事情的选择?循环的 ...不会遍历非整数(自己的枚举)属性。如果没有其他选择,为什么他们不赞成呢?
According to the MDN page at for each...in loop, this construct is deprecated. Is there an alternative that does exactly the same thing? The for...of loop does not iterate over non-integer (own enumerable) properties. If there isn't an alternative, why did they deprecate it then?
推荐答案
替代方案完全相同的事情?
for ...在
循环中,您首先要做的在代码块中是将 foo [propertyname]
复制到一个变量中。
A for ... in
loop in which the first thing you do in the block of code is to copy foo[propertyname]
to a variable.
这篇关于JavaScript替代“每个”循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文