i have a complex array structure as shown below,
array=[
{ 'mm': '1', exp: 'exp1' },
{ 'mm': '2', exp: 'exp2' },
{ 'mm': [ '1', '3', '7' ], exp: 'exp3' },
{ 'mm': [ '1', '2', '4', '6' ], exp: 'exp4' },
{ 'mm': [ '1', '3', '2' ], exp: 'exp5' },
{ 'mm': [ '8', '2', '9' ], exp: 'exp6' },
{ 'mm': [ '4', '7', '1', '2' ], exp: 'exp7' },
{ 'mm': [ '5', '6', '2', '4', '3', '8', '1' ], exp: 'exp8' }
]
i am looking for a way to restructure this array by flipping keys with values and vice versa. The expected output should look like this:
[
{ 'mm': '1', exp: ['exp1','exp3','exp4',','exp5','exp7','exp8'] },
{ 'mm': '2', exp: ['exp2','exp4','exp5','exp6','exp7','exp8'] },
{ 'mm': '3', exp: ['exp3','exp5','exp8'] },
{ 'mm':'4', exp:['exp4','exp7','exp8'] },
{ 'mm':'5', exp:['exp8'] },
{ 'mm':'6', exp:['exp4','exp8'] },
{ 'mm':'7', exp: ['exp3','exp7'] },
{ 'mm':'8', exp: ['exp6','exp8] },
{ 'mm':'9', exp: ['exp6'] }
]
i would appreciate any efficient solutions or suggestions while i continue working on solving this problem myself.