Skip to content

Instantly share code, notes, and snippets.

@goldalworming
Created January 23, 2021 07:44
Show Gist options
  • Save goldalworming/4f9305d06ae5a5c9356706102241b20f to your computer and use it in GitHub Desktop.
Save goldalworming/4f9305d06ae5a5c9356706102241b20f to your computer and use it in GitHub Desktop.
datamilestone = [
{milestone_id:"Dog1", milestone_name:"Spot"},
{milestone_id:"Cat1", milestone_name:"Tiger"},
{milestone_id:"Dog2", milestone_name:"Rover"},
{milestone_id:"Cat2", milestone_name:"Leo"}
];
datastage = [
{kode:"Dog1", stage:1},
{kode:"Cat2", stage:3}
];
//=============== object hasil groupby
objstage = {
"Dog1" : [{kode:"Dog1",stage:1}],
"Cat2" : [{kode:"Cat2",stage:3}]
}
//masukan data obj ke datamilestone saat looping
for (var i = 0; i < datamilestone.rows.length; i++) {
key = datamilestone.rows[i].milestone_id
datamilestone.rows[i].stage = obj[key]['stage']
}
//hasilnya
datamilestone = [
{milestone_id:"Dog1", milestone_name:"Spot", stage:1},
{milestone_id:"Cat1", milestone_name:"Tiger", stage:''},
{milestone_id:"Dog2", milestone_name:"Rover", stage:''},
{milestone_id:"Cat2", milestone_name:"Leo", stage:3}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment