Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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);
	   }
Source by github.com #
 
PREVIOUS NEXT
Tagged: #Sort #Array #Object #React
ADD COMMENT
Topic
Name
3+3 =