Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort string array object javascript

let strArray = [{name: 'c' }, {name: 'a' }, {name: 'd' }, {name: 'b' }];


console.log(strArray.sort((a, b) => a.name.localCompare(b.name)))

// nodejs
console.log(strArray.sort((a, b) => a.name.localeCompare(b.name)))
Comment

sort string array object javascript

obj.sort(function(a,b){
  if(a.last_nom< b.last_nom) return -1;
  if(a.last_nom >b.last_nom) return 1;
  if(a.first_nom< b.first_nom) return -1;
  if(a.first_nom >b.first_nom) return 1;
  return 0;
});
Comment

sort string array object javascript

function dynamicSort(property) {
    var sortOrder = 1;
    if(property[0] === "-") {
        sortOrder = -1;
        property = property.substr(1);
    }
    return function (a,b) {
        /* next line works with strings and numbers, 
         * and you may want to customize it to your needs
         */
        var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
        return result * sortOrder;
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: grapql file upload 
Javascript :: listen to changes in children of div in html 
Javascript :: globalevariable reactjs 
Javascript :: Process.ChildProcess._handle.onexit 
Javascript :: js version error 
Javascript :: remove duplicates by id 
Javascript :: internation number 
Javascript :: createTextFinder matchcase example 
Javascript :: javascript cast everything to string 
Javascript :: createelement and set prop attr jquery 
Javascript :: jest run current file 
Javascript :: isnumber javascript function 
Javascript :: javaascript localStorage get number, not string 
Javascript :: how to get the value of state of on and off 
Javascript :: Search products from an array by keywords in javascript 
Javascript :: exercice json 
Javascript :: tictactoe using Jquery 
Javascript :: import js with vite ts 
Javascript :: like and dislike function 
Javascript :: Reactjs exemple function component 
Javascript :: Day of The Year 
Javascript :: Access the list of valid values for an Enum field in a MongoDb Mongoose Schema 
Javascript :: Schalte das jQuery Migrate Script ab 
Javascript :: javasript vetical menu cog 
Javascript :: reactRender 
Javascript :: fetch hook 
Javascript :: Nodemailer Reuseable Code 1 
Javascript :: react native asyncstorage mergeItem 
Javascript :: appolo query data in angular graphql 
Javascript :: “javascript sleep 1 second” is a pretty common code problem that people search ;-) 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =