I am trying to retrieve values back in a nested array but my function is returning back everything. I would like to just back the 'carTime' values in my array.
What my array is returning.
[
{
"carId": "13122",
"carInstances": [
{
"carInstanceId": "472",
"carTime": "2020-09-23T21:45:00.000+0000",
"state": "COMPLETE",
}
],
"isPaused": false,
},
{
"carId": "1312",
"carInstances": [
{
"carInstanceId": "47209",
"carTime": "2020-09-23T21:45:00.000+0000",
"state": "COMPLETE",
}
],
"isPaused": false,
},
]
Lodash:
const result = [
{
"carId": "13122656",
"carInstances": [
{
"carInstanceId": "47209",
"carTime": "2020-09-23T21:45:00.000+0000",
"state": "COMPLETE",
}
],
"isPaused": false,
},
{
"carId": "1312",
"carInstances": [
{
"carInstanceId": "4720",
"carTime": "2020-09-23T21:45:00.000+0000",
"state": "COMPLETE",
}
],
"isPaused": false,
},
]
const findCategoryById = (sections) => {
const jobInstance = _.forEach(sections, (section) => {
return section.carInstances.carTime;
});
return jobInstance;
};
findCategoryById(result)
Desired Output:
2020-09-23T21:45:00.000+0000,
2020-09-23T21:45:00.000+0000