这是数组:
var level:Array = new Array( 5 ); //there are five rows
level[0] = [0.01, 0.6116, 0.001000, 206.14, 0.00, 2375.3, 0.00, 2501.4, 0.0000, 9.1562]
level[1] = [5, 0.8721, 0.001000, 147.12, 20.97, 2382.3, 20.98, 2510.6, 0.0761, 9.0257]
level[2] = [10, 1.2276, 0.001000, 106.38, 42.00, 2389.2, 42.01, 2519.8, 0.1510, 8.9008]
level[3] = [15, 1.7051, 0.001001, 77.93, 62.99, 2396.1, 62.99, 2528.9, .02245, 8.7814]
level[4] = [20, 2.339, 0.001002, 57.79, 83.95, 2402.9, 83.96, 2538.1, 0.2966, 8.6672]
我想输入一个数字并找到该数字的匹配项,将该行的值返回到每个数字的特定字段。例如,如果我在输入字段中输入数字10,我想要数字1.2276,0.00100,106.38以及该行的其余部分输出这些值
我见过很多选择,不知道从哪里开始。感谢。
答案 0 :(得分:1)
使用简单的for
循环。
for (var i:int=0; i<level.length; i++) {
if (level[i].indexOf(input) > -1) { // check array for index of input
trace(level[i]);
break; // stop loop because we're done
}
}
答案 1 :(得分:0)
我建议使用Dictionary
而不是Array
。这样,您可以将键分配给Array
对象,并按键访问数组。
var level:Dictionary = new Dictionary();
level[0.01] = [0.6116, 0.001000, 206.14, 0.00, 2375.3, 0.00, 2501.4, 0.0000, 9.1562];
level[5] = [0.8721, 0.001000, 147.12, 20.97, 2382.3, 20.98, 2510.6, 0.0761, 9.0257];
level[10] = [1.2276, 0.001000, 106.38, 42.00, 2389.2, 42.01, 2519.8, 0.1510, 8.9008];
level[15] = [1.7051, 0.001001, 77.93, 62.99, 2396.1, 62.99, 2528.9, .02245, 8.7814];
level[20] = [2.339, 0.001002, 57.79, 83.95, 2402.9, 83.96, 2538.1, 0.2966, 8.6672];
function getArrayByInputText(txt:String):Array {
return level[txt];
}
trace(getArrayByInputText("10")); // [1.2276, 0.001000, 106.38, 42.00, 2389.2, 42.01, 2519.8, 0.1510, 8.9008];