这是一个过于简化的示例,但我很好奇如何按日期顺序返回对象(从最新到最旧)而不更改数组顺序:
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...
]
答案 0 :(得分:0)
只需迭代外部数组,取出每个内部数组并对其进行排序:
for(const array of arrayOfArrays) {
array.sort(/*...*/);
}
您可以详细了解排序的工作原理here