Here are two arrays, how can I quickly sort one array based on another?
var MainArray = [{
guid: '24c2b868-8f4d-4113-a537-f8e7f57bb88b',
info: 'photo 1'
}, {
guid: '27e910cf-ba4c-412c-9faf-e7db5f058639',
info: 'photo 2'
}, {
guid: '66fc9e12-1c0a-447c-81c8-2f3a4bf0608c',
info: 'photo 3'
}, {
guid: 'f2afa8a9-6666-44d5-b360-8e7b8fb27c2e',
info: 'photo 4'
}, {
guid: '6d670044-9d3e-4c48-ba2b-5ec3e0c6be0f',
info: 'photo 5'
}];
var newArray = [{
id: 1,
name: 'name1',
guid: '6d670044-9d3e-4c48-ba2b-5ec3e0c6be0f'
}, {
id: 2,
name: 'name2',
guid: 'f2afa8a9-6666-44d5-b360-8e7b8fb27c2e'
}, {
id: 3,
name: 'name3',
guid: '66fc9e12-1c0a-447c-81c8-2f3a4bf0608c'
}, {
id: 4,
name: 'name4',
guid: '27e910cf-ba4c-412c-9faf-e7db5f058639'
}, {
id: 5,
name: 'name5',
guid: '24c2b868-8f4d-4113-a537-f8e7f57bb88b'
}];
I need to sort the new Array based on the guid of the MainArray, what's the best way to achieve this?