I have a JS object that I am trying to loop through and change values of.
Example of the object below:
var response = {
'2433345':
[
{
taskId: 20295179,
stageId: 'AB-5R-GF',
},
{
taskId: 20295176,
stageId: 'AB-5R-GF',
},
],
'2539643':
[
{
taskId: 28295179,
stageId: 'AB-5R-RD',
},
{
taskId: 20445176,
stageId: 'AB-5R-ZZ',
},
]
}
The parent values are JobIDs, then an array with nested objects for each stage and task within that job.
I am trying to iterate through and change the stageID values to sequential numbers. Each number in a job higher than the last, keeping duplicates the same number.
The desired result would be:
var response = {
'2433345':
[
{
taskId: 20295179,
stageId: 1,
},
{
taskId: 20295176,
stageId: 1,
},
],
'2539643':
[
{
taskId: 28295179,
stageId: 1,
},
{
taskId: 20445176,
stageId: 2,
},
]
}
I am wondering what the best approach would be to solve this? Would using Lodash and _.uniqBy be the best way?