Javascript alphabetical grouping
问题 I have a json array of objects that look like this: {id:'the id', name:'the name'}; and I need to loop over the array and group each object alphabetically by it's name attribute. Is there a way to do this without using a switch / if statement with every letter in it? What I don't want to do is something like this: if(data[i].name..slice(0, 1) == 'a') { ... } It's a large array, with almost a 1,000 objects in it. My goal is eventually append them to a dive so it looks something like this: 4 4