JavaScipt routine that counts to number of times the word is in the string

Job ID: 34526896

Budget: $10 – $30 USD

I need a JavaScript routine that will count the number of times a word is in the file. The word needs to be the complete word. The file that I uploaded has the word "Smoking" 5 times and "Smoking Cessation" 6 times and "Smoking Cessation Agents" once. Do not reference Smoking in the cessation or Agents. Put the values in a multi array or JSON file. I need the information to produce a DataTable and a Word Cloud.

The code I'm posting works fine but I want cleaner code. I need to search for complete word and ignore case and ignore the comma. If you can write cleaner/faster code. Please bid

Get_Counts(arg){
let words = "";

??this produces the attached file
for (var i = 0; i < this.publicationData.length; i++) {
words += this.publicationData[i]["NCI_MeshTerms"]
}

// The attached file has the words


const arr = words.split(',')
console.log(words)
let unique_words = [...new Set(arr)]
console.log(unique_words.length)
words += ","
for (var i = 0; i < unique_words.length; i++) {
var word = unique_words[i];
var regex = new RegExp( word + ',' , 'g' );
var count = words.match(regex).length;
console.log(word + ' ' + count);
}

},
Related categories: JavaScript HTML5 Regular Expressions