Languages
[Edit]
EN

TypeScript - get sorted object properties by value

0 points
Created by:
Palus-Bear
1016

In this article, we would like to show you how to sort object properties by value in TypeScript.

Practical example

Edit

The example shows how to sort obj object properties by value using Object.entries() method which returns the object's [key/value] pairs in the same order as a for...in loop.
Then we sort entries array with .sort() method passing arrow function that compares values. 

Output:

Note:

Above solution is safe because, it behaves like for ... in loop with checking condition if an object has a specific own property (like Object.prototype.hasOwnProperty()).

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join