I still working on a jQuery script that output under the Ckeditor the list of the most repeated words. Is not a keywords density but just a list of words and their repeats, excluding stop words both in english and Italian, plus some html clean-out. Is based on Bootstrap, jQuery and Ckeditor.
I've made this JSFiddle example that works good: https://jsfiddle.net/wzh7c42f/
the problem is if I wrote in any position inside a text in textarea the word "map" the function KeyDensityShow raise an error, and to be precise in the line
word_counts[positions[word]][1]++
I've not found a solution or why it give an error. If someone could help out to find the reason and provide a fix or a better optimization I will be very grateful.
ty in advance
EDIT:
Using the provided solution i fixed my code and works perfectly. this is the functional version on JSFiddle: https://jsfiddle.net/09m7c2hw/