Answer the question
In order to leave comments, you need to log in
Typescript how to sort by name?
Good evening, guys, how to sort not by key but by name
var stringArray: string[] = ['sd', 'Stas', 'Dima', 'AC'];
var sortedArray: string[] = stringArray.sort((n1,n2) => {
if (n1 > n2) {
return 1;
}
if (n1 < n2) {
return -1;
}
return 0;
});
Answer the question
In order to leave comments, you need to log in
You need to write a coolness function and sort not just by name, but by the value of the coolness function from the name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question