I have an array of objects with several key value pairs, and I need to sort them based on \'updated_at\':
[
{
\"updated_at\" : \"2012-01-01T06:25
You could use the Lodash utility library to solve this problem (it's quite an efficient library):
const data = [{
"updated_at": "2012-01-01T06:25:24Z",
"foo": "bar"
},
{
"updated_at": "2012-01-09T11:25:13Z",
"foo": "bar"
},
{
"updated_at": "2012-01-05T04:13:24Z",
"foo": "bar"
}
]
const ordered = _.orderBy(
data,
function(item) {
return item.updated_at;
}
);
console.log(ordered)
You can find documentation here: https://lodash.com/docs/4.17.15#orderBy