JavaScriptSort an array of objects using javascript

function sortByProperty(arr, property) {
  return arr.sort((a, b) => (a[property] > b[property] ? 1 : -1));
}

Related Snippets

Cover Image for Create a cover image

Create a cover image

Loading...
Cover Image for Convert a string to title case in javascript

Convert a string to title case in javascript

Loading...
Cover Image for Create a countdown timer

Create a countdown timer

Loading...
Cover Image for Fibonacci sequence in javascript

Fibonacci sequence in javascript

Loading...
Cover Image for Find the second largest number in an array.  in javascript

Find the second largest number in an array. in javascript

Loading...
Cover Image for Get the keys from an objects using javascript

Get the keys from an objects using javascript

Loading...