Languages
[Edit]
EN

JavaScript - ordered object properties

20 points
Created by:
Dollie-Rutledge
806

In this article, we would like to show how to achieve object that stores ordered properties in JavaScript.

In JavaScript, object properties are not ordered by default, but it is possible to work with ordered properties only when we use:

  • some logic that sorts properties, that requires re-sort operation on each change,
  • embedded Map class,
  • custom implementation of Map class.

 

Embedded Map class usage example

Edit

Note: this approach has been introduced in ES2015.

Output (with NodeJS):

 

Custom implementation of Map class

Edit

In this article you can find custom implementation of Map class that stores items in ordered way.

 

References

Edit
  1. Map class - MDN docs

Alternative titles

  1. JavaScript - ordered map
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