I know this must be relatively simple, but I have a dataset of JSON that I would like to sort by date. So far, I’ve run into problems at every turn.
Right now I have the date stored as this.lastUpdated.
I have access to jquery if that helps, but I realize the .sort() is native JS.
Thanks in advance.
I know this must be relatively simple, but I have a dataset of JSON
Share
Assuming that you have an array of javascript objects, just use a custom sort function:
The Array
sortmethod sorts an array using a callback function that is passed pairs of elements in the array.ain this case), will precede the second argument (b) in the sorted array.bprecedesain the sorted array.You can read more on the
sortmethod here.