Created
March 22, 2022 09:26
-
-
Save rashid327/57eeda357e8a38dcf375c34b68d20264 to your computer and use it in GitHub Desktop.
find specific word and their count in array object in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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