for..in循环遍历非数字索引“clean”和“remove” [英] for..in loop loops over non-numeric indexes “clean” and “remove”

查看:255
本文介绍了for..in循环遍历非数字索引“clean”和“remove”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我可能在这里失踪的一些非常基本的东西,但是直到现在我还没有看到这样的结果。



我有一个for循环,其中options.headers.length是 3 。在for循环中,我动态创建一个表头。理想情况下,这个循环应该为 0 1和2 运行三次,但是当我打印索引时,它会打印 0,1,2,clean and remove 。我没有看到清理并删除作为索引。我知道这个信息是不够的,但如果你有任何线索,请建议。我的调试结果也是如此。

  for(index.headers中的索引)$ b $如果你不想遍历 


解决方案 clean 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆