How can I show the frequency of every single word contained in a div or textarea? I found this thread that comes close to what I need, but I need to get the text from an element and not from the string
function getFrequency2(string, cutOff) {
var cleanString = string.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,""),
words = cleanString.split(' '),
frequencies = {},
word, frequency, i;
for( i=0; i<words.length; i++ ) {
word = words[i];
frequencies[word] = frequencies[word] || 0;
frequencies[word]++;
}
words = Object.keys( frequencies );
return words.sort(function (a,b) { return frequencies[b] -frequencies[a];}).slice(0,cutOff).toString();
}
document.write( getFrequency2( "1 2 1 2 3 1 2 3 1 1 4 test", 3 ) );