【发布时间】:2022-08-18 15:26:26
【问题描述】:
const objectTest = {
Shoes: [
{ id: 1, name: \"xxx\", image: \"xxxxxx\" },
{ id: 2, name: \"yyy\", image: \"yyyyyy\" },
],
Top: [
{ id: 1, name: \"zzz\", image: \"zzzzzz\" },
{ id: 2, name: \"aaa\", image: \"aaaaaa\" },
],
};
我知道我可以使用 find 方法。
const item = objectTest.Shoes.find((p) => p.name === \"xxx\");
console.log(item); ///{id: 1, name: \'xxx\', image: \'xxxxxx\'}
但是如果我不知道“xxx”属于Shoes 组怎么办。如何找到\"xxx\" 并返回{ id: 1, name: \"xxx\", image: \"xxxxxx\" }
标签: javascript