I am building an Angular 9 app. In this app I need to sort one array using another array.
This is the first array:
[{
"field_key": "title",
"field_type": "text",
"field_label": "Title",
"rows": [{
"id": 267255299,
"content": "Personal task"
}, {
"id": 568449863,
"content": "Super"
}, {
"id": 110557130,
"content": "Another child"
}, {
"id": 365047528,
"content": "Another task"
}, {
"id": 383976941,
"content": "Nice"
}, {
"id": 811735335,
"content": "Arrays"
}, {
"id": 324862914,
"content": "Arrays"
}, {
"id": 485226870,
"content": "Yay a child"
}, {
"id": 276334971,
"content": "My new task"
}, {
"id": 549277506,
"content": "Douplicatee"
}]
}, {
"field_key": "progress",
"field_type": "progress",
"field_label": "Progress",
"rows": [{
"id": 267255299,
"content": null
}, {
"id": 568449863,
"content": null
}, {
"id": 110557130,
"content": 100
}, {
"id": 365047528,
"content": 100
}, {
"id": 383976941,
"content": null
}, {
"id": 811735335,
"content": null
}, {
"id": 324862914,
"content": 100
}, {
"id": 485226870,
"content": null
}, {
"id": 276334971,
"content": 60
}, {
"id": 549277506,
"content": 0
}]
}, {
"field_key": "ends_at_date",
"field_type": "date",
"field_label": "Due date",
"rows": [{
"id": 267255299,
"content": null
}, {
"id": 568449863,
"content": null
}, {
"id": 110557130,
"content": null
}, {
"id": 365047528,
"content": null
}, {
"id": 383976941,
"content": null
}, {
"id": 811735335,
"content": null
}, {
"id": 324862914,
"content": null
}, {
"id": 485226870,
"content": "2020-08-25"
}, {
"id": 276334971,
"content": "2020-08-16"
}, {
"id": 549277506,
"content": null
}]
}]
This is the array I want to use to sort the first array. The "key" key in the second array is the same value as the "field_key" in the first array. So I guess I should be able to use these values to do the sorting.
[{
key: 'title',
label: 'Title',
field: 'text',
visible: true
}, {
key: 'ends_at_date',
label: 'Due date',
field: 'date',
visible: true
}, {
key: 'progress',
label: 'Progress',
field: 'progress',
visible: true
}]
I want to reorder/sort the first array so that it is in the same order as the last array based upon the key/field_key values. Right now the order of the first array is: Title, Progress, Ends_at_date but the order of the second array (the correct one) is Title, Ends_at_date, Progress.