gpt4 book ai didi

javascript - 在对象数组中查找所有匹配的元素

转载 作者:搜寻专家 更新时间:2023-11-01 04:56:00 24 4
gpt4 key购买 nike

<分区>

我有一个对象数组

我正在这样的数组中搜索

let arr = [
{ name:"string 1", arrayWithvalue:"1,2", other: "that" },
{ name:"string 2", arrayWithvalue:"2", other: "that" },
{ name:"string 2", arrayWithvalue:"2,3", other: "that" },
{ name:"string 2", arrayWithvalue:"4,5", other: "that" },
{ name:"string 2", arrayWithvalue:"4", other: "that" },
];
var item = arr.find(item => item.arrayWithvalue === '4');
console.log(item)

这应该返回包含这两行的数组

{ name:"string 2", arrayWithvalue:"4,5", other: "that" },
{ name:"string 2", arrayWithvalue:"4", other: "that" }

它只返回第一个匹配的一行。

{ name:"string 2", arrayWithvalue:"4", other: "that" }

我不想为此使用任何外部库。如何返回所有符合条件的匹配项?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com