0
我想循环一个JavaScript对象结构来查找一些数据,当我找到这些数据时,跳出循环。迭代一个JavaScript对象
喜欢的东西[伪代码]:
obj = { /*All the structure*/ };
while (i < lenght of obj structure) or (the data I was looking for wasn't found){
//(...)
}
的问题是,我不能得到该结构的长度和我不能以while
迭代它。
这样做的方法是什么?
使用'for in'循环。 – SLaks
这是非常昂贵的,因为我的对象非常大 –
使用'break':https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break。您只能使用'for ... in'循环遍历一个对象。 –