I have this array:
It has 16 positions and each position is an object with an ID and a content. I have to order this array alphabetically by it’s content. I tried to use sort, but it didn’t work. Can someone help me with this ?
Advertisement
Answer
You should implement the sort method like that:
JavaScript
x
4
1
elems.sort(function(a, b) {
2
return a.content - b.content;
3
});
4
Or using ES6:
JavaScript
1
2
1
elems.sort((a, b) => a.content - b.content);
2