我有以下物件,并想獲取月份等于“2022-04-01”的“payroll_run_items”,所以…… 就像鍵值 Foo 的兄弟鍵的值。
{
"payrollRuns": [
{
"company": {
"id": 1,
"name": "Example Ltd.",
"country": "Germany",
"city": "Munich",
"zip": "80801",
"street": "Max-Strasse",
"house_number": "3",
"vat": "DE12434",
"customer_number": "1",
"fee_offer": "59.00",
"is_active": true
},
"month": "2022-06-01",
"amount": "733.00",
"line_items": 1,
"payroll_run_items": []
},
{
"company": {
"id": 1,
"name": "Example Ltd.",
"country": "Germany",
"city": "Munich",
"zip": "80801",
"street": "Max-Strasse",
"house_number": "3",
"vat": "DE12434",
"customer_number": "1",
"fee_offer": "59.00",
"is_active": true
},
"month": "2022-04-01",
"amount": "7570.02",
"line_items": 2,
"payroll_run_items": [
"{amount: \"3749.00\", id: 68, month: {…}, offer: {…},…}",
"{amount: \"3821.02\", id: 73, month: {…}, offer: {…},…}"
]
}
],
"setPayrollRuns": "? bound dispatchSetState() {}"
}
到目前為止,我想出的只是獲取所有密鑰,但是我現在如何檢查“2022-04-01”并將“payroll_run_items”分配給變數?
const payrollLineItems = () => (
Object.keys(props.payrollRuns)
)
uj5u.com熱心網友回復:
find月份匹配條件的物件,并提取您想要的屬性值。
const data={payrollRuns:[{company:{id:1,name:"Example Ltd.",country:"Germany",city:"Munich",zip:"80801",street:"Max-Strasse",house_number:"3",vat:"DE12434",customer_number:"1",fee_offer:"59.00",is_active:!0},month:"2022-06-01",amount:"733.00",line_items:1,payroll_run_items:[]},{company:{id:1,name:"Example Ltd.",country:"Germany",city:"Munich",zip:"80801",street:"Max-Strasse",house_number:"3",vat:"DE12434",customer_number:"1",fee_offer:"59.00",is_active:!0},month:"2022-04-01",amount:"7570.02",line_items:2,payroll_run_items:['{amount: "3749.00", id: 68, month: {…}, offer: {…},…}','{amount: "3821.02", id: 73, month: {…}, offer: {…},…}']}]};
const out = data.payrollRuns.find(obj => {
return obj.month === '2022-04-01';
}).payroll_run_items;
console.log(out);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/467355.html
標籤:javascript
下一篇:試圖對懸停圖片進行故障排除
