如何通过知道要删除的记录的值来删除数组或对象中的记录

时间:2017-10-17 12:31:15

标签: javascript jquery

我有一个数组如下

[
    { id: "172~~81259", title: "Absurdity (Theatre)" },
    { id: "2803~~281318", title: "Academic Administration" },
    { id: "3722~~296974", title: "Accessories Design" },
    { id: "23843", title: "Accommodation and Front Office Professional" },
    { id: "16834", title: "Accountant" },
    { id: "853~~64400", title: "Accounting Information System" },
    { id: "4403~~40149", title: "Activation and Experiential Advertising" },
    { id: "15~~39301", title: "Activation and Experiential Advertising" }
]

我想过滤(删除)此数组中已选择的值。如何通过仅知道值来过滤。

1 个答案:

答案 0 :(得分:2)

您需要array.filter。它生成一个新数组,其中只包含导致提供的回调返回true的项。使用该回调来检查您要检查的值,无论该值是什么。