react sort by value code example
Example 1: sort function in react js
this.state.data.sort((a, b) => a.timeM > b.timeM ? 1:-1).map(
(item, i) => <div key={i}> {item.matchID} {item.timeM} {item.description}</div>
)
Example 2: 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)