Javascript - sort objects in an array alphabetically on one property of the array
<p>Let's say you have a javascript class like this...</p>

<pre><code>var DepartmentFactory = function(data) {
    this.id = data.Id;
    this.name = data.DepartmentName;
    this.active = data.Active;
}
</code></pre>

<p>Let's say you then create a number of instances of that class and store them in an array...</p>

<pre><code>var objArray = [];
objArray.push(DepartmentFactory({Id: 1, DepartmentName: 'Marketing', Active: true}));
objArray.push(DepartmentFactory({Id: 2, DepartmentName: 'Sales', Active: true}));
objArray.push(DepartmentFactory({Id: 3, DepartmentName: 'Development', Active: true}));
objArray.push(DepartmentFactory({Id: 4, DepartmentName: 'Accounting', Active: true}));
</code></pre>

<p>So I now would have an array of objects created by DepartmentFactory.  How would I go about using the array.sort() method to sort this array of objects by the DepartmentName property of each object?</p>

<p>The array.sort() method works just fine when sorting an array of strings...</p>

<pre><code>var myarray=["Bob", "Bully", "Amy"];
myarray.sort(); //Array now becomes ["Amy", "Bob", "Bully"]
</code></pre>

<p>But how do I make it work with a list of objects?</p>

<p>Thanks.</p>
