带环对象的jQuery的滤波器阵列 [英] Jquery filter array of object with loop
本文介绍了带环对象的jQuery的滤波器阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象,像这样的数组:
I have an array of objects like this:
myArray = [
{label: "a",
value: "100"},
{label: "b",
value: "101"},
{label: "c",
value: "102"}
...
我要过滤这样的:
I want to filter it like this:
myArrayFiltered = myArray.filter(function(v){
return v["value"] == "101" || v["value"] == "102"});
将返回
myArrayFiltered = [
{label: "b",
value: "101"},
{label: "c",
value: "102"}]
在这个例子中,但我想和值数组做的过滤器。我该怎么做?
in this example but I want to do the filter with an array of values. How can I do that ?
推荐答案
只是检查,如果你筛选的价值是你的阵列中的
Just check if the value you're filtering on is in your array
myArrayFiltered = myArray.filter(function(v){
return ["102", "103"].indexOf(v.value) > -1;
});
这篇关于带环对象的jQuery的滤波器阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文