Is there a way to extract names from the provided JSON, based on an array of IDs?
[
{
"id": 0,
"name": "salesTransNo"
},
{
"id": 1,
"name": "terminalNo"
},
{
"id": 2,
"name": "salesTransDate"
},
{
"id": 3,
"name": "salesTransTime"
},
{
"id": 4,
"name": "exceptionAmount"
},
{
"id": 5,
"name": "laneNumber"
}
]
The desired outcome is to have an array containing only the names from the JSON data, given an array of id
values.
For example: array of ids: [2, 4, 5]
The expected output should be:
["salesTransDate", "exceptionAmount", "LaneNumber"]
How can this be achieved using Lodash or JavaScript?
I attempted to use _.find
and _.map
to retrieve only the name from the result. However, it seems to work only for a single value input, rather than an array like [2, 4, 5].