Created
January 16, 2023 09:35
-
-
Save Dinir/3c1265b96e4253d197d323984d45115f to your computer and use it in GitHub Desktop.
Extract values from JSON, so it can be used to get the wordcount.
This file contains 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 getWordsOfJSONObj = obj => { | |
let valueText = '' | |
for (key in obj) { | |
if (typeof obj[key] === 'object') { | |
valueText += getWordsOfJSONObj(obj[key]) | |
} else { | |
valueText += obj[key] + '\n' | |
} | |
} | |
return valueText | |
} | |
const getWordsOfJSON = jsonText => getWordsOfJSONObj(JSON.parse(jsonText)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment