Quantcast
Viewing latest article 15
Browse Latest Browse All 56

Answer by Ben Aston for Sorting javascript object by number (value), then abc order by string (key)

Using the clever technique found in another answer:

const words = {"be": 3,"a": 5,"an": 3}const sortedEntries = (o) =>     Object.entries(words)          .sort(([k1, v1], [k2, v2]) =>               v2 - v1 || k1.localeCompare(k2))console.log(sortedEntries(words))

Viewing latest article 15
Browse Latest Browse All 56

Trending Articles