簡體   English   中英

for循環無法在Javascript中正確獲取數組長度

[英]for loop not picking up the array length properly in Javascript

 for (var i=0; i<10; i++) {
                this.videos[i].url = 'http://localhost:27017/' + 
this.videos[i].url;
            this.videos[i].avgRating = 0;
            for(var j=0;j<this.videos[i].rating.length;j++){
                this.videos[i].avgRating += this.videos[i].rating[j];
            }

第二個for循環導致錯誤“無法獲取未定義或空引用的屬性'length'”

該錯誤表示“第i個視頻元素”中的“評級”未初始化。 您是否在打外循環之前已驗證視頻數組已完全初始化?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM