Search
 
SCRIPT & CODE EXAMPLE
 

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);
	   }
Comment

react sort an object by an element

const vehicle = [ 
 { type: 'car', color: 'Red' },
 { type: 'car', color: 'Blue' },
 { type: 'truck', color: 'Black' } ]

vehicle.sort((a, b) => a.type.localeCompare(b.type));
//vehicle.sort(compareFn:(a :vehicle, b :vehicle) => a.type.localeCompare(b.type));
Comment

PREVIOUS NEXT
Code Example
Typescript :: rename table of contents latex 
Typescript :: typescript type of children 
Typescript :: ffmpeg batch convert ts to mp4 files in a folder 
Typescript :: object of strings typescript 
Typescript :: react native typescript children prop 
Typescript :: docker An attempt was made to access a socket in a way forbidden by its access permissions. 
Typescript :: show grants user 
Typescript :: typescript req.query.query 
Typescript :: err_too_many_redirects wordpress 
Typescript :: how to link locally installed fonts to css 
Typescript :: golang terminal prompts disabled 
Typescript :: adoni db:seed 
Typescript :: setstate typescript type 
Typescript :: stripe typescript 
Typescript :: Bulk Products Selection on sales process odoo 
Typescript :: skip specific test in jasmine 
Typescript :: e typescript 
Typescript :: google sheets empty functions 
Typescript :: nodemon.ps1 cannot be loaded because running scripts is disabled on this system. 
Typescript :: ionic pasword visible inside ion-input 
Typescript :: denoot deno 
Typescript :: sort list of lists by first element 
Typescript :: angular get item from localstorage 
Typescript :: typescript add one month to date 
Typescript :: typescript add to array 
Typescript :: vue3 backend django 
Typescript :: ionic 3 open link external 
Typescript :: is assigned a value but never used 
Typescript :: yup type validation error message 
Typescript :: echarts is not defined 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =