I'm trying to do a counter object in JavaScript like so: EDIT: I've added an example
let profile={skill:['javascript','javascript','html','css','css']}
let objectCount={}
profiles.map(profile => {
profile.skills.map(skill => {
skill = skill.toLowerCase();
if (!(skill in objectCount)) {
objectCount = { ...objectCount, [skill]: 1 };
} else {
objectCount.skill = objectCount.skill + 1;
}
});
});
}
I have array of profiles and inside them an array of skills which is : 'javascript','html','css',etc and I wish to make an objectCount that will be:
objectCount={
'html':1,
'javascript:2,
'css':2
}
but for some reason the line
objectCount.skill=objectCount.skill+1 doesnt work, because I get an object with 1 in every single key,
does anybody know whats my error?