When adding new words do this: word.replace(/./g," ").replace(/ +/g," ").trim() Also delete this word which shows ugliness of the current implementation: http://jbovlaste.lojban.org/dict/.i