My task involves sorting the properties of objects in an array based on the sequence of another array.
let arrToSort = [
{ Architect: 'Terry', Client: 'AZ', ClientType: 'Kids', Location: 'USA'},
{ Architect: 'Mary', Client: 'XY', ClientType: 'Clothes', Location: 'Germany'},
{ Architect: 'Jerry', Client: 'BC', ClientType: 'Construction', Location: 'Canada'}
];
let accordingTo = ["ClientType", "Architect", "Location", "Client"];
The desired output is as follows:
finalArr = [
{ ClientType: 'Kids', Architect: 'Terry', Location: 'USA', Client: 'AZ'},
{ ClientType: 'Clothes', Architect: 'Mary', Location: 'Germany', Client: 'XY'},
{ ClientType: 'Construction', Architect: 'Jerry', Location: 'Canada', Client: 'BC'}
]