resultObj =
{
"userId": "2",
"username": "Atul",
"userEmail": "mishra.atul1@dalmiacement.com",
"role": [
{
"id": "1",
"roleName": "Admin",
"userId": null,
"roleId": null,
"selected": "1"
},
{
"id": "5",
"roleName": "Zone",
"userId": null,
"roleId": null,
"selected": "1"
}
],
"area": [
{
"regionId": "EAST",
"stateId": "EAST~BHN",
"districtId": "-1"
},
{
"regionId": "EAST",
"stateId": "EAST~BHS",
"districtId": "-1"
}
]
}
let roleZoneobj = {};
Object.entries(resultObj).forEach(([key, value]) =>
{
if(key === "role")
{
value.forEach((elr, index) =>
{
if(elr.roleName === "Zone")
{
roleZoneobj['role'] = "zone";
}
})
}
if(key === "area")
{
value.forEach((els, index) =>
{
if(els.stateId === "EAST~BHN")
{
roleZoneobj['bhn'] = "EAST~BHN";
}
if(els.stateId === "EAST~BHS")
{
roleZoneobj['bhs'] = "EAST~BHS";
}
})
}
});
console.log(roleZoneobj)
if(roleZoneobj.role === "zone" &&
roleZoneobj.bhn === "EAST~BHN")
{
console.log("good")
}
// https://www.freecodecamp.org/news/how-to-iterate-over-objects-in-javascript/
// https://itnext.io/x1f4f9-3-ways-to-loop-over-object-properties-with-vanilla-javascript-es6-included-efb4a68cfbb
// https://www.freecodecamp.org/news/how-to-loop-through-an-array-in-javascript-js-iterate-tutorial/
//https://medium.com/p/940f7721a609
// https://medium.com/byprogrammers/6-different-ways-to-loop-through-an-array-in-javascript-with-examples-10a65e604b8
// https://flexiple.com/loop-through-object-javascript/
//https://flaviocopes.com/how-to-iterate-object-properties-javascript/
//https://code.tutsplus.com/articles/how-to-iterate-over-object-properties-in-javascript--cms-39656
No comments:
Post a Comment