Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort obj by its property name

const sortByProperty = (array, propertyName) => {
    return array.sort(function (a, b) {
        if (a[propertyName] < b[propertyName]) {
            return - 1
        } else if (a[propertyName] > b[propertyName]) {
            return 1
        }
        return 0
    });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #obj #property
ADD COMMENT
Topic
Name
5+3 =