I have an array which contains many objects. I am trying to sort the array based on the key value of each object.
So, the object looks like this:
var info = [
{name: 'Adam', age: '1987-01-09T18:23:20.000Z'},
{name: 'Issac', age: '1988-09-02T11:17:11.000Z'},
{name: 'Tom', age: '2003-08-07T13:07:03.000Z'},
{name: 'Jane', age: '1997-17-01T14:57:41.000Z'}
];
I am trying saved the new (sorted) data into a variable called sorted;
var sorted = info.forEach(function(person) {
var age = moment(String(person.age)).format('MM/DD/YYYY');
return age
}, this);
console.log(sorted)
So, I have momentjs, to change the date into a time format that can easily be
sorted, but the sorted console.log shows me undefined.
Honestly, I don't even know how sorting functions work. At least it should return the age from the loop and thus console.log() should not have been empty
sort, or use something likelodash:_.sortBy(info, ['name', 'age']);-- lodash.com/docs/4.17.4#sortBy