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>
)
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>
)
Sort Array Object in React
const[dataValue, setDataValue] = useState([]);
const filter = () => {
let datafil = filterdataArray; // Array Filter Data Here
+ let val = datafil.sort(function (a, b) {
+ let dateA = a.name.toLowerCase();
+ let dateB = b.name.toLowerCase();
+ if (dateA < dateB) {
+ return -1;
+ } else if (dateA > dateB) {
+ return 1;
+ }
+ return 0;
+ });
+ setDataValue(val);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us