0

I have the following JSON data. It's an array of two objects.

The first object ("accounts") is an array of objects. I am attempting to access the last object in this array, and get into it's 'balances' object. I then want to access the final account (the second one) and pull the final 'available' from it.

[{
    "accounts": [{
            "account_id": "test",
            "balances": {
                "available": 3.45,
                "current": 3.45,
                "iso_currency_code": "GBP",
                "limit": null,
                "unofficial_currency_code": null
            },
            "mask": null,
            "name": "test",
            "official_name": null,
            "subtype": "savings",
            "type": "depository"
        },
        {
            "account_id": "test",
            "balances": {
                "available": 1500,
                "current": 1500,
                "iso_currency_code": "GBP",
                "limit": null,
                "unofficial_currency_code": null
            },
            "mask": null,
            "name": "test",
            "official_name": null,
            "subtype": "savings",
            "type": "depository"
        }
    ],
    "item": {
        "available_products": ["balance", "identity"],
        "billed_products": ["auth", "transactions"],
        "consent_expiration_time": "2021-04-20T13:49:20Z",
        "error": null,
        "institution_id": "ins_117243",
        "item_id": "test",
        "webhook": ""
    },
    "request_id": "999",
    "status_code": 200
}]

I want to do this either through mapping or dot notation.

The data is stored in a React front-end, inside of state.

Can someone tell me how best to get access to the available in the final balances object within the accounts array.

This would be "1500".

Barmar
  • 741,623
  • 53
  • 500
  • 612
Jon Nicholson
  • 927
  • 1
  • 8
  • 29

0 Answers0