I have a candidate object with properties
candidateid:number; name:string;
I want to sort an array of such objects based on a property name. How can I achieve this in TypeScript in angular 2?
name
This is the same as regular old javascript. You can use the 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))
Source: https://habr.com/ru/post/1656686/More articles:Javascript, ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠ³ΠΎ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ ΠΏΡΠΈ Π½Π°ΠΆΠ°ΡΠΈΠΈ ΠΊΠ½ΠΎΠΏΠΊΠΈ - javascriptC # Tuple Equality vs Contains List - c #WatchViewStub Π£ΡΡΠ°ΡΠ΅Π»Π° - androidHow to configure routing in Apache? - htmlSpring boot and JUnit with H2 JPA calls "pg_class" not found - javaHow to portablely create a class at run time in Common-Lisp CLOS - common-lispNSPersistentContainer Π΄ΠΎΡΡΡΠΏΠ΅Π½ ΡΠΎΠ»ΡΠΊΠΎ Π² Π²Π΅ΡΡΠΈΠΈ 10.0 ΠΈΠ»ΠΈ Π½ΠΎΠ²Π΅Π΅: ΠΎΡΠΈΠ±ΠΊΠ° - iosHow can I extract a reaction fragment in its own component? - reactjsCore EF6 ASP.NET ID - asp.netΠΡΠΎΠ±ΡΠ°ΠΆΠ°ΡΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»ΡΡΠΊΠΈΠΉ ΡΠΎΠ²Π°Ρ meta Π² ΠΊΠΎΡΠ·ΠΈΠ½Π΅ Ρ ΠΏΠΎΠ»ΡΠΌΠΈ ΠΏΠΎΠ²ΡΠΎΡΠΈΡΠ΅Π»Ρ acf - phpAll Articles