Skip to content

Instantly share code, notes, and snippets.

@rashid327
Created March 22, 2022 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashid327/57eeda357e8a38dcf375c34b68d20264 to your computer and use it in GitHub Desktop.
Save rashid327/57eeda357e8a38dcf375c34b68d20264 to your computer and use it in GitHub Desktop.
find specific word and their count in array object in javascript
const object1 = {
a: 'NO',
b: 'NO',
c: 'Yes',
d: 'NO',
};
//console.log(Object.values(object1));
function getWordCount(array) {
let map = {};
for (let i = 0; i < array.length; i++) {
let item = array[i];
map[item] = (map[item] + 1) || 1;
}
return map.NO;
}
console.log(getWordCount(Object.values(object1)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment