Skip to content

Instantly share code, notes, and snippets.

@kylelambert101
Created August 20, 2020 00:41
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 kylelambert101/b4f96e613de652559f50625d87cadbe7 to your computer and use it in GitHub Desktop.
Save kylelambert101/b4f96e613de652559f50625d87cadbe7 to your computer and use it in GitHub Desktop.
JavaScript -> Sort a list of objects
const myList = [
{ title: "First one", link: "https://en.wikipedia.org" },
{ title: "Second One", link: "https://en.wikipedia.org" },
{ title: "Actual First One", link: "https://en.wikipedia.org" },
];
// Sort the list by {each}.title, alphabetically
const sortedList = myList.sort((a, b) => (a.title > b.title ? 1 : -1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment