嗨我有一个应用程序,我有一半的工作。我有一组对象,每个对象的属性已经设置好,可以像这样调用它们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