我有一个对象数组。
我正在按照以下方式在数组中搜索。
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" }
我不想使用任何外部库来实现这个功能。如何返回所有符合条件的匹配项?