for..in循环遍历非数字索引“clean”和“remove” [英] for..in loop loops over non-numeric indexes “clean” and “remove”
问题描述
我有一个for循环,其中options.headers.length是 3
。在for循环中,我动态创建一个表头。理想情况下,这个循环应该为 0 1和2
运行三次,但是当我打印索引时,它会打印 0,1,2,clean and remove
。我没有看到
清理并删除
作为索引。我知道这个信息是不够的,但如果你有任何线索,请建议。我的调试结果也是如此。
for(index.headers中的索引)$ b $如果你不想遍历
remove
然后改变循环为: for(var i = 0; i< options.headers.length; i ++){
//使用i获取数组
如果您使用 for(index.headers中的index)
,它会迭代非数字
键。
This is something very basic I might be missing here but I haven't seen such result till now.
I have a for loop where options.headers.length is 3
. And in for loop I am dynamically creating a table header. Ideally this loop should run three times for 0 1 and 2
but when I have printed index it's printing 0,1,2,clean and remove
. I haven't seen clean and remove
as indexes. I know this information is not sufficient enough but if you have any clue please suggest. something might be overriding this is all I am concluded too after my debugging.
for (index in options.headers)
if you don't want to iterate clean
and remove
then change the loop to:
for (var i=0; i< options.headers.length;i++){
//use i for getting the array data
}
if you use for (index in options.headers)
it will iterate for non-numeric
keys also.
这篇关于for..in循环遍历非数字索引“clean”和“remove”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!