Several million words in memory (in JavaScript in a browser)? It sounds a lot, no matter what structure you decide to keep. Instead, you can consider other types of optimization, for example, loading subsets of your list of words based on the characters you type.
For example, if the user enters โa,โ then you will begin to extract all the words starting with โaโ. You can then optimize your list of words by first returning more common words, so more likely ones will match instantly, while less common words may load a little slower.
source share