JavaScript - Sort array of objects by object attribute

This helper can be used with the Array.sort(); method for sorting an array of objects by an objects attribute.

Usage:


    var a = [obj5,obj1,obj8,obj3,obj2,obj9,obj4,obj6,obj7];
    a.sort(arrange.byObjectsAttribute('name'));

Example:

Sort above list by: date - name

Code for this example here.

Acknowledgment:

This page is a result of techniques described by Douglas Crockford

Page by: Trygve Lie