Skip to content

Instantly share code, notes, and snippets.

View Eazybright's full-sized avatar
🏠
Working from home

Kolawole Ezekiel Eazybright

🏠
Working from home
View GitHub Profile
@Eazybright
Eazybright / sort-object-properties-by-value.md
Created November 13, 2019 06:28 — forked from umidjons/sort-object-properties-by-value.md
JavaScript: sort object properties by value (numeric or string)

Sort object properties by value (values are text)

I have following object:

var cities={10:'Tashkent', 14:'Karakalpakiya', 16:'Andijan'};

I want sort it by city names, so after sort it should be:

var cities={16:'Andijan', 14:'Karakalpakiya', 10:'Tashkent'};

But I can't sort object properties, instead can convert object into array, then sort items.