I have the following data structures:
const fieldOrder = [
'title',
'first_name',
'last_name',
'address_1',
'address_2',
'city',
'state',
'zipcode',
'country',
]
const fields = [
{
name: 'first_name',
value: 'John'
},
{
name: 'title',
value: 'Mr'
}
...etc
]
And I'd like to reorder the fields array of objects based on the position of the name key in the fieldOrder array. How is this possible? Perhaps with the Array.sort method somehow?
And, generally speaking, is this the best way to represent order?