How can I order an object by its indices in JavaScript, with an object similar to the following
{ave:2,gato:3,burro:7,caballo:3,hipopotamo:5,elefante:8}
How can I make the object look like this?
{ave:2,burro:7,caballo:3,elefante:8,gato:7,hipopotamo:5}
You can get the keys with the Object.keys() method , then sort them with
sort()
, and finally build a new object.With Sort By Underscore