Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort by attribute in reactjs

const list = [
  { qty: 10, size: 'XXL' },
  { qty: 2, size: 'XL' },
  { qty: 8, size: 'M' }
]

list.sort((a, b) => (a.qty - b.qty) ? 1 : -1)

console.log(list)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #attribute #reactjs
ADD COMMENT
Topic
Name
2+8 =