带有循环的对象的 Jquery 过滤器数组 [英] Jquery filter array of object with loop

查看:19
本文介绍了带有循环的对象的 Jquery 过滤器数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的对象数组:

I have an array of objects like this:

myArray = [
{label: "a", 
value: "100"},
{label: "b",
value: "101"},
{label: "c",
value: "102"}
...

我想像这样过滤它:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆