I got an array (see below for one object in the array) that I need to sort by firstname using JavaScript. How can I do it?
var user = { bio: null, emai
Pushed the top answers into a prototype to sort by key.
Array.prototype.alphaSortByKey= function (key) { this.sort(function (a, b) { if (a[key] < b[key]) return -1; if (a[key] > b[key]) return 1; return 0; }); return this; };