Answers for "how to sort Alphabetically of object"

2

sort object alphabetically javascript

//Sort object by v1 property alphabetically (case insensitive)
let objArray= [
  {v1:"Bee", v2: 2}, 
  {v1:"Apple", v2: 8}, 
  {v1:"bat", v2: 4},
];
let sortedArray= objArray.sort(function(a, b) {
   return a.v1.localeCompare(b.v1);
}); // [{v1: "Apple", v2: 8}, {v1: "bat", v2: 2}, {v1: "Bee", v2: 2}]
Posted by: Guest on April-30-2021
0

how to sort Alphabetically of object

let objArray= [
  {v1:Bee, v2: 2}, 
  {v1:Apple, v2: 8}, 
  {v1:bat, v2: 4},
];
let sortedArray= objArray.sort(function(a, b) {
   return a.v1.localeCompare(b.v1);
});
Posted by: Taylor Swift on March-10-2022

Code answers related to "how to sort Alphabetically of object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language