-3

I have this array:

enter image description here

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 ?

afr
  • 19
  • 6
  • 3
    Please always, always, always include the code you are asking about as text, not pictures of text. And, show what you've tried (even if it didn't work). – Scott Marcus Aug 03 '20 at 20:55
  • 3
    Please show code and data as text, not as a picture of text. Use `console.log(JSON.stringify(arr, null, 2))` to get a good representation, then copy a representative portion of that data. – Heretic Monkey Aug 03 '20 at 20:56
  • 3
    Does this answer your question? [Sort array of objects by string property value](https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value) – jarmod Aug 03 '20 at 20:56

1 Answers1

2

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);
Rodrigo Silva
  • 463
  • 3
  • 10