如果一个键满足某个值,我需要过滤一个数组,例如:
data = theArray;
var theColumn = "thc012";
var theVal = 4;
data = $.filter(data, theColumn, theVal );
然后结果将是匹配 theColumn = theVal ;
我已经在使用 jQuery 库,所以如果有任何 jQuery 函数有帮助,请使用它们。
谢谢
最佳答案
Javascript 对象是键值对。你可以使用它们。 像这样:
var data = {
"cars": ["Honda", "Toyota", "Subaru"],
"planes": ["Boeing", "Airbus", "Mig"]
};
var key = "cars";
data[key]; // All cars
key = "planes";
data[key]; // All planes
关于Javascript [jQuery] 按键和值过滤数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7146203/