sort array by property react code example
Example: 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)
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)