I have an array with items and I want to group them according the first letter but when I push the item to the array it shows empty "Array[0]" while there are clearly items in it.
Apparently I'm doing something wrong but i have no idea what.
var group = [];
var alphabetArray = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
alphabetArray.forEach(function(letter) {
group[letter] = group[letter] || [];
group[letter].push({
key: letter,
letter
});
});
console.log(group);
AB, just for first two characters. I still have no idea what exactly are you looking for.