Created
June 22, 2020 05:08
-
-
Save tejasrsuthar/a16803f627baa30c18322bbe297499f8 to your computer and use it in GitHub Desktop.
Normal Array of Objects sort by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const usCityOptions = cities | |
// Object sorting by key | |
.sort((a, b) => { | |
if(a.state < b.state){ | |
return -1; | |
// a should come after b in the sorted order | |
}else if(a.state > b.state){ | |
return 1; | |
// and and b are the same | |
}else{ | |
return 0; | |
} | |
}) | |
.map((o) => <option key={o.state} value={o.state}>{o.state}</option>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment