嗨我有一個應用程序,我有一半的工作。我有一組對象,每個對象的屬性已經設置好,可以像這樣調用它們myarray[i].property
。我有一個if語句,可以在循環內搜索數組,並在任何地方提取出myarray[i].property == my var
。如何使用JavaScript循環創建一個對象數組
我遇到的問題是,我想把這些結果放入一個新的數組中,該數組由搜索第一個數組的if語句/循環組合構建,並且我無法使其工作。
這是我試過的,但失敗了?
var c = 0;
var matches = new Array('application', 'sclass', 'type', 'motor', 'bearings', 'gears', 'modelno', 'name', 'speed', 'v3_3', 'v4_8', 'v6_0', 'v7_2', 'weight', 'diensions', 'opvoltage', 'image', 'description');
//loop through servos array and pull any servo that has a matching application value to that selected by the search filter
for(var i=0; i < servos.length; i++){
if servos[i].application == document.searchFilters.applicationMenu.value) {
//populate the new 'matches' array with the details from the servos pulled from the inital arary
matches[c] = new servo(servos[i].application, servos[i].sclass, servos[i].type, servos[i].motor, servos[i].bearings, servos[i].gears, servos[i].modelno, servos[i].name, servos[i].speed, servos[i].v3_3, servos[i].v4_8, servos[i].v6_0, servos[i].v7_2, servos[i].weight, servos[i].dimensions, servos[i].opvoltage, servos[i].image, servos[i].description);
c++;
} else if (document.searchFilters.applicationMenu.value == 0){
//sets the value of servoDtore locally
var servoStore = 0;}
此外,在代碼中,我也行document.getElementById('servoDisplay').innerHTML = "search result " + matches[c].modelno; //display servos model numbers stored within the matches array
我要去哪裏錯了,爲什麼我總是得到「.modelno null或undefined」錯誤,每當我打電話比賽[C]。型號?
我假設'mew'實際上是'new'? –
y只是一個錯字,因爲我沒有複製和粘貼代碼,因爲它在這個不同的電腦 –
你有沒有重置C的價值? – geekchic