Javascript 是否根据月份筛选对象列表?
我使用图形,所以每当我选择根据月份显示数据时,我必须显示每个月的数据,我有totalAmount、paidAmount等字段,我应该对该月的数据求和Javascript 是否根据月份筛选对象列表?,javascript,reactjs,Javascript,Reactjs,我使用图形,所以每当我选择根据月份显示数据时,我必须显示每个月的数据,我有totalAmount、paidAmount等字段,我应该对该月的数据求和 const myArray = [ { "id": 9, "userId": null, "invoiceNumber": "biscuitInvoice", "billedBy": 1, "bi
const myArray = [
{
"id": 9,
"userId": null,
"invoiceNumber": "biscuitInvoice",
"billedBy": 1,
"billedTo": 2,
"addGst": false,
"invoiceDate": "2021-05-08T12:05:00",
"dueDate": "2021-05-21T12:03:00",
"totalAmount": 11.8,
"discountSymbol": null,
"discountPercent": null,
"subTotal": null,
"notes": null,
"signature": null,
"reachMail": "",
"reachPhoneNo": null,
"businessLogo": null,
"clientName": "Checking Business",
"businessName": "Chocolate Business",
"paymentAmount": 140,
"status": "Created",
"igst": 1.8,
"cgst": 0,
"amount": null,
"sgst": 0,
"businessClient": null,
"businessProfile": null,
"invoiceAttachments": [],
"invoiceItems": [],
"invoiceTerms": []
},
{
"id": 8,
"userId": null,
"invoiceNumber": "invq32",
"billedBy": 1,
"billedTo": 3,
"addGst": false,
"invoiceDate": "2021-04-04T10:10:22",
"dueDate": "2021-05-13T10:10:00",
"totalAmount": 354,
"discountSymbol": null,
"discountPercent": null,
"subTotal": null,
"notes": null,
"signature": null,
"reachMail": "",
"reachPhoneNo": null,
"businessLogo": null,
"clientName": "Checking",
"businessName": "Chocolate Business",
"paymentAmount": 120,
"status": "Paid",
"igst": 54,
"cgst": 0,
"amount": null,
"sgst": 0,
"businessClient": null,
"businessProfile": null,
"invoiceAttachments": [],
"invoiceItems": [],
"invoiceTerms": []
}
]
在那个列表中,我有invoiceDate,一个对象是四月,另一个是五月
有什么帮助吗?以下是您需要的功能:
函数getDesiredMonth(数据,月份){
返回数据.filter((项目)=>item.invoiceDate.split(“-”[1]”)==month)
}
例如,您可以这样调用它以获取五月发票:
getDesiredMonth(myArray,'05')
让我知道这是否适合你:)回答,因为我没有足够的代表发表评论 我想你可以遵循以下步骤:
total\u sgst+=current\u obj.sgst
)做什么。。。到底是什么问题?月在哪里?是基于日期吗?是的,基于日期,根据该对象中的invoiceDate Hanks bro,我会尝试让你知道谢谢@Elvaleryn成功了,如果你接受我的答案,我会非常感激,然后尝试让你知道
function filterDataByMonth(data, month){
return data.filter(i => new Date(i.invoiceDate).getMonth() + 1 === month);
}