-1

This is an overly simplified example, but I'm curious how I can return the objects in order by date (newest to oldest) without changed the array order at all:

let arrayOfArrays = [
    array1 = [
        object1 = {id: 1, name: 'object1', created_date: '2012-01-15'},
        object2 = {id: 2, name: 'object2', created_date: '2018-01-15'},
        object3 = {id: 3, name: 'object3', created_date: '2018-01-17'}
    ],
    array2 = [
        object4 = {... created_date: '2013-01-15'},
        object5 = {... created_date: '2017-01-15'},
        ...and so on...
    ],
    ...more arrays...
]

Here's an actual image of what I'm attempting to sort: enter image description here

Matt Larsuma
  • 1,456
  • 4
  • 20
  • 52

1 Answers1

0

Just iterate over the outer array, take every inner array and sort that:

 for(const array of arrayOfArrays) {
   array.sort(/*...*/);
 }

You can find out more on how sort works here

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • Actually, realizing that I'm really trying to sort just an array of objects and the reason it isn't working is that some of the objects are empty. It's an array of addresses and some of the addresses have an array of account objects. – Matt Larsuma Apr 18 '18 at 14:06