You could use a chained sorting approach by taking the delta of values until it reaches a value not equal to zero.

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);
.as-console-wrapper { max-height: 100% !important; top: 0; }

Or, using es6, simply:

data.sort((a, b) => a.city.localeCompare(b.city) || b.price - a.price);
Answer from Nina Scholz on Stack Overflow
🌐
TypeOfNaN
typeofnan.dev › sort-array-objects-multiple-properties-javascript
How to sort an array of objects by multiple properties in JavaScript | TypeOfNaN
March 20, 2023 - This actually ends up being fairly similar to our last example except this time we sort each element of the array using a property: const arr = [ { name: 'Mike', age: 20 }, { name: 'Peter', age: 30 }, { name: 'Doris', age: 18 }, ]; arr.sort((a, b) => a.age - b.age); console.log(arr); /* [ { name: 'Doris', age: 18 }, { name: 'Mike', age: 20 }, { name: 'Peter', age: 30 }, ] */ Finally, we have our goal case: sorting objects by multiple properties.
Discussions

Sort array of objects by multiple properties in Javascript - Stack Overflow
I've been reading similar posts all day but can't figure out how to sort my javascript array by multiple properties. My array has a 'name' and 'type' property. To sort by name I now use: ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Sorting an array of objects by property values - Stack Overflow
Here is a slightly modified version ... book "JavaScript: The Good Parts". NOTE: This version of by is stable. It preserves the order of the first sort while performing the next chained sort. I have added isAscending parameter to it. Also converted it to ES6 standards and "newer" good parts as recommended by the author. You can sort ascending as well as descending and chain sort by multiple properties... More on stackoverflow.com
🌐 stackoverflow.com
JavaScript sort array of objects on multiple properties by specific constant values - Stack Overflow
How do I sort by the objects properties in the array where bankType of "Checkings" are sorted first then currency of "CAD" accounts are sorted next to achieve the following result below? More on stackoverflow.com
🌐 stackoverflow.com
Day 57: How Do You Sort an Array of Objects by Multiple Properties in JavaScript?
You can find an answer to this question and hundreds others on javascript-tips. No need to make an account on Medium. https://javascript-tips.weebly.com/array-tips-complete.html More on reddit.com
🌐 r/JavaScriptTips
1
0
August 2, 2025
🌐
Serhii Shramko
shramko.dev › home › snippets › sort an array of objects by multiple properties
How to Sort an Array of Objects by Multiple Properties in JavaScript
October 13, 2024 - data.sort((a, b) => { if (a.name !== b.name) { return a.name.localeCompare(b.name); } else if (a.age !== b.age) { return a.age - b.age; } else { return a.city.localeCompare(b.city); } }); console.log(data); // Output: [ { name: 'Anna', age: 22, city: 'London' }, { name: 'John', age: 25, city: 'Paris' }, { name: 'John', age: 30, city: 'New York' }, { name: 'Mike', age: 32, city: 'New York' }, ]; JavaScript Arrays — deep dive into array methods including sort, map, and filter
🌐
TutorialsPoint
tutorialspoint.com › sort-an-array-of-objects-by-multiple-properties-in-javascript
Sort an array of objects by multiple properties in JavaScript
const arr = [ { id: 1, score: 1, isCut: false, dnf: false }, { id: 2, score: 2, isCut: false, dnf: false }, { id: 3, score: 3, isCut: false, dnf: false }, { id: 4, score: 4, isCut: false, dnf: false }, { id: 5, score: 5, isCut: true, dnf: true }, { id: 6, score: 6, isCut: true, dnf: false }, { id: 7, score: 7, isCut: true, dnf: false }, { id: 8, score: 8, isCut: true, dnf: false }, { id: 9, score: 9, isCut: true, dnf: false }, { id: 10, score: 0, isCut: false, dnf: false }, { id: 11, score: -1, isCut: false, dnf: false }, { id: 12, score: -2, isCut: false, dnf: true }, { id: 13, score: -3, isC
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-sort-an-array-of-object-by-two-fields-in-javascript
How to sort an array of object by two fields in JavaScript ? | GeeksforGeeks
June 26, 2024 - // Create input array of objects let arr = [ { first: 3, second: 4 }, { first: 3, second: 1 }, { first: 1, second: 10 } ]; // Apply array.sort with custom comparision funtion arr.sort(function (a, b) { // Compare first value then second return a.first - b.first || a.second - b.second; }); // Display the output console.log("'" + JSON.stringify(arr[0]) + ", " + JSON.stringify(arr[1]) + ", " + JSON.stringify(arr[2]) + "'"); Output · '{"first":1,"second":10}, {"first":3,"second":1}, {"first":3,"second":4}' In this approach, we create a dynamic comparison function that accepts the properties to sort by as parameters. This makes the function reusable for different sets of properties without hardcoding the property names. JavaScript ·
🌐
TutorialsPoint
tutorialspoint.com › article › sort-array-of-objects-by-two-properties-in-javascript
Sort Array of objects by two properties in JavaScript
March 15, 2026 - // Define array of people const people = [ { name: 'Preeti', age: 25 }, { name: 'Aman', age: 30 }, { name: 'Shekhar', age: 20 }, { name: 'Preeti', age: 22 }, { name: 'Aman', age: 25 }, { name: 'Anjali', age: 28 } ]; const sortedPeople = people.sort((first, second) => { // First sort by name if (first.name < second.name) return -1; if (first.name > second.name) return 1; // If names are equal, sort by age if (first.age < second.age) return -1; if (first.age > second.age) return 1; return 0; // If both properties are equal }); console.log(sortedPeople); [ { name: 'Aman', age: 25 }, { name: 'Aman
Find elsewhere
🌐
Ben Ilegbodu
benmvp.com › blog › quick-way-sort-javascript-array-multiple-fields
Quick way to sort a JavaScript array by multiple fields | Ben Ilegbodu
It's now our responsibility to tell the method which object should go first based on the number we return and .sort does the rest. Keep in mind. Even though .sort returns an array it actually mutates the source array by sorting in place.
🌐
Reddit
reddit.com › r/javascripttips › day 57: how do you sort an array of objects by multiple properties in javascript?
r/JavaScriptTips on Reddit: Day 57: How Do You Sort an Array of Objects by Multiple Properties in JavaScript?
August 2, 2025 - https://javascript-tips.weebly.com/array-tips-complete.html · Search functions · r/DesignHomeGame • · upvotes · · comments · Did a little refactoring. r/Seablock • · 2 · upvotes · · comments · Data Structures in Python Visualized · r/datastructures • · upvotes · · comments · Day 47: Can You Sort an Array of Objects by a Property in JavaScript?
🌐
DEV Community
dev.to › markbdsouza › js-sort-an-array-of-objects-on-multiple-columns-keys-2bj1
JS: Sort an Array of Objects on multiple columns/keys - DEV Community
April 22, 2021 - Now say we want to sort this data across one column. The best way to do this is the sort() method. Check out the documentation. An example from there down below on a simple array of Strings
🌐
Vultr Docs
docs.vultr.com › javascript › examples › sort array of objects by property values
JavaScript Program to Sort Array of Objects by Property ...
December 18, 2024 - Sorting arrays of objects by property values in JavaScript is a straightforward process once you master the use of the sort() method with appropriate comparator functions. From numeric and string properties to more complex multi-property sorting, ...
Top answer
1 of 16
5805

It's easy enough to write your own comparison function:

function compare( a, b ) {
  if ( a.last_nom < b.last_nom ){
    return -1;
  }
  if ( a.last_nom > b.last_nom ){
    return 1;
  }
  return 0;
}

objs.sort( compare );

Or inline (c/o Marco Demaio):

objs.sort((a,b) => (a.last_nom > b.last_nom) ? 1 : ((b.last_nom > a.last_nom) ? -1 : 0))

Or simplified for numeric (c/o Andre Figueiredo):

objs.sort((a,b) => a.last_nom - b.last_nom); // b - a for reverse sort
2 of 16
1112

You can also create a dynamic sort function that sorts objects by their value that you pass:

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;
    }
}

So you can have an array of objects like this:

var People = [
    {Name: "Name", Surname: "Surname"},
    {Name:"AAA", Surname:"ZZZ"},
    {Name: "Name", Surname: "AAA"}
];

...and it will work when you do:

People.sort(dynamicSort("Name"));
People.sort(dynamicSort("Surname"));
People.sort(dynamicSort("-Surname"));

Actually this already answers the question. Below part is written because many people contacted me, complaining that it doesn't work with multiple parameters.

Multiple Parameters

You can use the function below to generate sort functions with multiple sort parameters.

function dynamicSortMultiple() {
    /*
     * save the arguments object as it will be overwritten
     * note that arguments object is an array-like object
     * consisting of the names of the properties to sort by
     */
    var props = arguments;
    return function (obj1, obj2) {
        var i = 0, result = 0, numberOfProperties = props.length;
        /* try getting a different result from 0 (equal)
         * as long as we have extra properties to compare
         */
        while(result === 0 && i < numberOfProperties) {
            result = dynamicSort(props[i])(obj1, obj2);
            i++;
        }
        return result;
    }
}

Which would enable you to do something like this:

People.sort(dynamicSortMultiple("Name", "-Surname"));

Subclassing Array

For the lucky among us who can use ES6, which allows extending the native objects:

class MyArray extends Array {
    sortBy(...args) {
        return this.sort(dynamicSortMultiple(...args));
    }
}

That would enable this:

MyArray.from(People).sortBy("Name", "-Surname");
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-sort-an-array-of-objects-by-property-values
How to sort an array of objects by property values ? | GeeksforGeeks
May 22, 2024 - The below approaches can be used to sort an array of objects using a value in TypeScript: Table ... Sorting is the process of arranging elements in a specific order. In JavaScript, you can sort a JSON array by value using various methods as listed and discussed below with their practical implementation.
🌐
GitConnected
levelup.gitconnected.com › sort-array-of-objects-by-two-properties-in-javascript-69234fa6f474
Sort Array of Objects By Two Properties in JavaScript | by Code & Coins | Level Up Coding
March 13, 2023 - I was recently working on a way to sort an array of objects alphabetically based on two columns. This means that both levels of alphabetical sorting should be maintained.
🌐
freeCodeCamp
forum.freecodecamp.org › general
javaScript: sorting an array with multiple object/properties - General - The freeCodeCamp Forum
December 4, 2019 - Hello every one, I am trying to build a card game using javaScript. I have used the .sort() method to reorder my deck of cards. My array is composed by a value: int number and a string: the card’s suit.