Skip to content

Instantly share code, notes, and snippets.

@kosinix
Last active August 6, 2021 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosinix/751d6094ca3656018b17114dc1e9691f to your computer and use it in GitHub Desktop.
Save kosinix/751d6094ca3656018b17114dc1e9691f to your computer and use it in GitHub Desktop.
Lodash Cheatsheet
// Sort array based on array of sorted IDs
let unsorted = [
{
id: 'bcd'
},
{
id: 'abc'
}
]
let idsArray = ['abc', 'bcd']
let sorted = lodash.sortBy(unsorted, (o) => {
return idsArray.indexOf(o.id)
});
// [ { id: 'abc' }, { id: 'bcd' } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment