|
- const fruits = [
- { name: "大苹果", order: 1 },
- { name: "小李子", order: 4 },
- { name: "大香蕉", order: 2 },
- { name: "小香蕉", order: 32 },
- { name: "大榴莲", order: 12 }
- ];
- function getApple(arr, value) {
- return arr.find((obj) => obj.name === value);
- }
- const result = getApple(fruits, "大榴莲");
- console.log(result);
复制代码 |
|