Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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}]
Comment

JavaScript sort array of objects by property alphabetically

var data = [{ h_id: "3", city: "Dallas", state: "TX", zip: "75201", price: "162500" }, { h_id: "4", city: "Bevery Hills", state: "CA", zip: "90210", price: "319250" }, { h_id: "6", city: "Dallas", state: "TX", zip: "75000", price: "556699" }, { h_id: "5", city: "New York", state: "NY", zip: "00010", price: "962500" }];

data.sort(function (a, b) {
    return a.city.localeCompare(b.city) || b.price - a.price;
});

console.log(data);
Comment

sort object alphabetically javascript

objArray.sort(function(a, b) {
    var textA = a.DepartmentName.toUpperCase();
    var textB = b.DepartmentName.toUpperCase();
    return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
});
Comment

js sort object properties alphabetically

const data = {
  States: ['NSW', 'VIC'],
  Countries: ['GBR', 'AUS'],
  Capitals: ['SYD', 'MEL']
}

const sortedObject = Object.fromEntries(Object.entries(data).sort())
Comment

PREVIOUS NEXT
Code Example
Javascript :: ajax request header laravel 
Javascript :: link next js target _blank 
Javascript :: giving height full in next image 
Javascript :: include partials ejs 
Javascript :: javascript detect touch screen 
Javascript :: javascript select element with attribute 
Javascript :: v-for i down 
Javascript :: react native scrollview horizontal 
Javascript :: javascript get current time 
Javascript :: content type json 
Javascript :: javascript biggest number 
Javascript :: javascript remove focus from button 
Javascript :: 419 unknown status ajax laravel 
Javascript :: get href attribute javascript 
Javascript :: ec2 yum nodejs 
Javascript :: disable input field from jquery 
Javascript :: js number 2 decimal places 
Javascript :: Your global Angular CLI version (11.0.2) is greater than your local version 
Javascript :: discord.js cooldown 
Javascript :: jquery min 
Javascript :: parsefloat jquery 
Javascript :: html string to html 
Javascript :: align text into center of container react native 
Javascript :: javascript get first 2 char 
Javascript :: node js delete folder with files 
Javascript :: npm ERR! code EACCES 
Javascript :: how to open browser for upload with click on element in jquery 
Javascript :: flash input js 
Javascript :: get text inside element javascript 
Javascript :: primera letra en mayuscula javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =