[{ "nameEng": "current", "nameChn": "电流", "children": [{ "nameEng": "phaseCurrentA", "nameChn": "相电流la", "children": null }, { "nameEng": "phaseCurrentB", "nameChn": "相电流lb", "children": null }, { "nameEng": "phaseCurrentC", "nameChn": "相电流lc", "children": null } ] }, { "nameEng": "lineVoltage", "nameChn": "线电压", "children": [{ "nameEng": "lineVoltageAb", "nameChn": "线电压Uab", "children": null }] }, { "nameEng": "frequency", "nameChn": "频率", "children": [{ "nameEng": "systemFrequency", "nameChn": "系统频率F", "children": null }] }, { "nameEng": "powerFactor", "nameChn": "功率因素", "children": [{ "nameEng": "powerFactorPb", "nameChn": "分相功率因数Pfb", "children": null }, { "nameEng": "powerFactorPc", "nameChn": "分相功率因数Pfc", "children": null } ] }, { "nameEng": "systemActivePower", "nameChn": "系统有功功率", "children": [{ "nameEng": "systemActivePowerP", "nameChn": "系统有功功率Psum", "children": null }] }, { "nameEng": "positiveActivePower", "nameChn": "总正向有功电度", "children": [{ "nameEng": "totalPositiveActivePower", "nameChn": "总正向有功电度 kWh", "children": null }] } ]这样的数组中我想用js的方法获取nameEn为‘powerFactorPb‘并返回这个对象’’
时间: 2023-07-05 22:36:42 浏览: 125
你可以使用数组的 `find` 方法来获取 `nameEng` 为 'powerFactorPb' 的对象,然后返回该对象。以下是示例代码:
```javascript
const data = [
{
"nameEng": "current",
"nameChn": "电流",
"children": [
{
"nameEng": "phaseCurrentA",
"nameChn": "相电流la",
"children": null
},
{
"nameEng": "phaseCurrentB",
"nameChn": "相电流lb",
"children": null
},
{
"nameEng": "phaseCurrentC",
"nameChn": "相电流lc",
"children": null
}
]
},
{
"nameEng": "lineVoltage",
"nameChn": "线电压",
"children": [
{
"nameEng": "lineVoltageAb",
"nameChn": "线电压Uab",
"children": null
}
]
},
{
"nameEng": "frequency",
"nameChn": "频率",
"children": [
{
"nameEng": "systemFrequency",
"nameChn": "系统频率F",
"children": null
}
]
},
{
"nameEng": "powerFactor",
"nameChn": "功率因素",
"children": [
{
"nameEng": "powerFactorPb",
"nameChn": "分相功率因数Pfb",
"children": null
},
{
"nameEng": "powerFactorPc",
"nameChn": "分相功率因数Pfc",
"children": null
}
]
},
{
"nameEng": "systemActivePower",
"nameChn": "系统有功功率",
"children": [
{
"nameEng": "systemActivePowerP",
"nameChn": "系统有功功率Psum",
"children": null
}
]
},
{
"nameEng": "positiveActivePower",
"nameChn": "总正向有功电度",
"children": [
{
"nameEng": "totalPositiveActivePower",
"nameChn": "总正向有功电度 kWh",
"children": null
}
]
}
];
const powerFactorPbObj = data.find(obj => obj.nameEng === 'powerFactorPb');
console.log(powerFactorPbObj);
```
输出结果应该为:
```javascript
{
"nameEng": "powerFactorPb",
"nameChn": "分相功率因数Pfb",
"children": null
}
```
阅读全文