Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)))
 
PREVIOUS NEXT
Tagged: #sort #string #array #object #javascript
ADD COMMENT
Topic
Name
9+8 =