sort an array by string in typescript code example
Example: how to sort string aray in ts
// TypeScript
const value = ['2020', '2017', '2019', '2018']
value.sort((a,b) => a < b ? -1 : a > b ? 1 : 0) // Ascending
value.sort((a,b) => a < b ? 1 : a > b ? -1 : 0) // descending
// javaScript
const value = ['2020', '2017', '2019', '2018']
Array.from(value).sort((a,b) => a-b) // Ascending
Array.from(value).sort((a,b) => b-a) // descending