R.E.M. Web Development

Sorting an array of objects by a property

I have an array that looks like this:

var people = [
{name: "John", age:15},
{name: "Betty", age:12},
{name: "Zach", age:22}


And I need to sort it by name, here's how to do it:

people = people.sort(function(a, b){

var aName = a.name.toLowerCase();
var bName = b.name.toLowerCase();

if(aName > bName) return 1;

if(aName < bName) return -1;

return 0;