Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

react sort an object by an element

const vehicle = [ 
 { type: 'car', color: 'Red' },
 { type: 'car', color: 'Blue' },
 { type: 'truck', color: 'Black' } ]

vehicle.sort((a, b) => a.type.localeCompare(b.type));
//vehicle.sort(compareFn:(a :vehicle, b :vehicle) => a.type.localeCompare(b.type));
Source by github.com #
 
PREVIOUS NEXT
Tagged: #react #sort #object #element
ADD COMMENT
Topic
Name
8+8 =