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 :: async await mongoose connection 
Javascript :: event loop 
Javascript :: custom attribute jquery selector 
Javascript :: How to Use the toUpperCase() String Method in javascript 
Javascript :: input type search clear event 
Javascript :: reverse int js 
Javascript :: javascript date to firebase timestamp 
Javascript :: lodash empty string 
Javascript :: access to xmlhttprequest has been blocked by cors policy react 
Javascript :: ajax with progress bar 
Javascript :: add class to element javascript 
Javascript :: Date gethours js 
Javascript :: javascript get element by id 
Javascript :: res.json in express 
Javascript :: how to add up all the numbers in between 0 and that number 
Javascript :: app.js:38650 [Vue warn]: Failed to mount component: template or render function not defined 
Javascript :: chart.js label word wrap 
Javascript :: hex string to int javascript 
Javascript :: how to get single element from nested array mongoose 
Javascript :: jquery navigation 
Javascript :: iterate through json object 
Javascript :: avoid no-param-reassign when setting a property 
Javascript :: reverse words in a string javascript 
Javascript :: js get last element of array 
Javascript :: how to read breakline in html 
Javascript :: css canvas set aspect ratio 
Javascript :: what is computed in mobx 
Javascript :: js set canvas size 
Javascript :: react form submit values with name 
Javascript :: date add hours javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =