Given the following:
var array = [{"name":"zoe", "hotdogs":5},{"name":"april", "hotdogs":5},{"name":"ryan", "hot dogs":8}]
How can I sort the elements of the array by name using JavaScript?
var array = [{"name":"april", "hotdogs":5},{"name":"ryan", "hotdogs":8},{"name":"zoe", "hotdogs":5}]
Is there a way to apply some function to sort the objects? Are there helper libraries that help with performance?
I tried the following:
array.sort(function(a, b) {
return a.name > b.name
});
But it appeared to have no effect on the resulting array when I try to print it out whatsoever.