月关宝盒
不确定要如何过滤它也会共享所需的输出以获得更好的清晰度。var data=[{owner: "76561198111463361",sold: true,inventory: [{ name: "AK-47 | Redline", }, { name: "StatTrak™ AWP | Asiimov",}],name: "m",password: "e",},{owner: "76561198111463361",sold: true,inventory: [{ name: "AK-47 | Redline", }, { name: "StatTrak™ AWP | Asiimov",}],name: "m",password: "e"}];var string = 'Redline';result = data.filter(val=>val.inventory.some(k=>k.name.toUpperCase().includes(string.toUpperCase())));console.log(result);如果这解决了您的问题,请告诉我。
手掌心
您可以映射和过滤数据。const findInventory = (data, fn) => { return data.reduce((array, item) => { let inventory = item.inventory; if (fn !== undefined) { inventory = inventory.map(fn); } array = array.concat(inventory); return array; }, []);};const data = [{"owner":"76561198111463361","sold":true,"inventory":[{"name":"AK-47 | Redline","price":1369},{"name":"StatTrak™ AWP | Asiimov","price":8050}],"name":"m","password":"e"},{"owner":"76561198111463361","sold":true,"inventory":[{"name":"AK-47 | Redline","price":1369},{"name":"StatTrak™ AWP | Asiimov","price":8050}],"name":"m","password":"e"}];// Get objectsconsole.log(findInventory(data));// get namesconsole.log(findInventory(data, (i) => i.name));第二个例子:const findInventory = (data, mapper, filter) => { return data.reduce((array, item) => { let inventory = item.inventory; if (mapper !== undefined && filter !== undefined) { inventory = inventory.map(mapper).filter(filter); } array = array.concat(inventory); return array; }, []);};const data = [{"owner":"76561198111463361","sold":true,"inventory":[{"name":"AK-47 | Redline","price":1369},{"name":"StatTrak™ AWP | Asiimov","price":8050}],"name":"m","password":"e"},{"owner":"76561198111463361","sold":true,"inventory":[{"name":"AK-47 | Redline","price":1369},{"name":"StatTrak™ AWP | Asiimov","price":8050}],"name":"m","password":"e"}];// Get objectsconsole.log(findInventory(data));// get names by filterconsole.log(findInventory(data, (i) => i.name, (name) => name.indexOf("AK-") !== -1));