I have a candidate object with properties
candidateid:number;
name:string;
I wish to sort an array of such objects based on the name property. How can I achieve this in TypeScript in angular 2?
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))
localeCompare - must have been a brit that wrote it... does not work in node fwiProperty 'foo' does not exist on type 'object'.ts(2339)nodejs? node and browser js use the same js engine..