I am looking to extract specific values from a MAP in JavaScript based on its id ("codi" within the object).
My array resembles the following but is larger:
0: {codi: '291', literal: 'MEDIFIATC Progres 2010 ', check: true}
1: {codi: '292', literal: 'MEDIFIATC Progres < 2010 ', check: true}
2: {codi: '293', literal: 'MEDIFIATC Progres ', check: true}
3: {codi: '294', literal: 'MEDIFIATC Progres 2013 ', check: true}
4: {codi: '295', literal: 'MEDIFIATC Progres 2014 ', check: true}
5: {codi: '296', literal: 'MEDIFIATC MEDIFIATC ', check: true}
6: {codi: '297', literal: 'MEDIFIATC MEDIFIATC P5 ', check: true}
7: {codi: '298', literal: 'MEDIFIATC MEDIFIATC P15 ', check: true}
8: {codi: '299', literal: 'MEDIFIATC MEDIFIATC DIAGONAL ', check: true}
Currently, I am using a simple loop where I iterate through and return the entry when my variable matches the "codi".
function getSubgroup(codi) {
for(j = 0; j < Object.keys(subGroupList).length; j++) {
if (codi == subGroupList[i].codi) {
return subGroupList[i];
}
}
}
How can I enhance this process?
In addition, I need to extract the values that I will be returning from my primary array. Currently using information from: How can I remove a specific item from an array? , any further assistance on this would be appreciated.
Thank you.
EDIT: I would like to share useful links here provided by Simone Rossaini in the comments: