Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #sort #string #aray #ts
ADD COMMENT
Topic
Name
3+8 =