How to sort object array based on key in typescript [duplicate]

It’s the same as plain old javascript. You can still use an arrow function to make it more concise.

x.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)

Or using localeCompare.

x.sort((a, b) => a.name.localeCompare(b.name))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)