I have two arrays:
alphabet is composed of letters (e.g. the English alphabet). dictionary is a list of objects with words and definitions, 'word' being the key for the word value.
I want to build a new array called frequency which would contain the number of words that start with each letter in the alphabet array, with indices corresponding to the alphabet array.
I've managed to come up with the following:
alphabet.forEach(function(letter) {
frequency = dictionary.filter(item => item['word'].toLowerCase().startsWith(letter)).length;
});
This gets me individual values for frequency. What is the best syntax in Javascript for building an array of those values? Is it another filter? Or should the code use the current forEach manually with a incremental index?
alphabetvariable and how you want the output result to bealphabet,dictionaryalso the expected value forfrequencyto make it more clear.