At the moment, I am working with an array that contains multiple objects
const bankData = [
{
"bank": "Chase",
"monthEndBalance": "72,175.88",
"bankStatementDate": "2020/10/31"
},
{
"bank": "Chase",
"monthEndBalance": "93,412.79",
"bankStatementDate": "2020/07/31"
},
{
"bank": "Chase",
"monthEndBalance": "88,175.88",
"bankStatementDate": "2020/11/30"
},
{
"bank": "Chase",
"monthEndBalance": "102,200.12",
"bankStatementDate": "2020/12/31"
},
{
"bank": "Goldman Sachs",
"monthEndBalance": "72,276.12",
"bankStatementDate": "2020/11/30"
},
{
"bank": "Goldman Sachs",
"monthEndBalance": "52,276.12",
"bankStatementDate": "2020/10/31"
},
{
"bank": "Goldman Sachs",
"monthEndBalance": "102,276.12",
"bankStatementDate": "2020/12/31"
},
{
"bank": "Wells Fargo",
"monthEndBalance": "33,276.12",
"bankStatementDate": "2020/11/30"
},
{
"bank": "Wells Fargo",
"monthEndBalance": "12,276.12",
"bankStatementDate": "2020/10/31"
},
{
"bank": "Wells Fargo",
"monthEndBalance": "150,276.12",
"bankStatementDate": "2020/12/31"
}
]
I am aiming to separate each bank into its own individual array of objects.
For example:
const bankOne = [
{
"bank": "Chase",
"monthEndBalance": "72,175.88",
"bankStatementDate": "2020/10/31"
},
{
"bank": "Chase",
"monthEndBalance": "93,412.79",
"bankStatementDate": "2020/07/31"
},
{
"bank": "Chase",
"monthEndBalance": "88,175.88",
"bankStatementDate": "2020/11/30"
},
{
"bank": "Chase",
"monthEndBalance": "102,200.12",
"bankStatementDate": "2020/12/31"
}
]
Although my current solution utilizes Array.filter
, it is not scalable and would require modification for every new bank added. What would be the most efficient method to filter each bank into its own unique array of objects?
const chaseBank = bankData.filter(el => el.bank === "Chase")
const goldManBank = bankData.filter(el => el.bank === "Goldman Sachs")
const wellsFargoBank = bankData.filter(el => el.bank === "Wells Fargo")