I have a keys array like ['D', 'B', 'A', 'C'] and object like below.
obj = [
{key: 'C', value: 'CCC'},
{key: 'B', value: 'BBB'},
{key: 'D', value: 'DDD'},
{key: 'A', value: 'AAA'}
]
What is the best way to sort that obj as the order of the keys like below, I prefer to use Lodash.
sorted_obj = [
{key: 'D', value: 'DDD'},
{key: 'B', value: 'BBB'},
{key: 'A', value: 'AAA'},
{key: 'C', value: 'CCC'}
]
I can think of the way to use additonal data structure like Map, but I really want to make this simple. Does anyone have a nice way to implement this? :)