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 ?
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 ?
You should implement the sort method like that:
elems.sort(function(a, b) {
return a.content - b.content;
});
Or using ES6:
elems.sort((a, b) => a.content - b.content);