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'循環遍歷一個對象。 –