I am trying to merge the array itself and convert it into a more meaningful array
array = [
{item: 'pen', madeIn: 'US', color: 'blue'},
{item: 'pen', madeIn: 'US', color: 'white'},
{item: 'pen', madeIn: 'China', color: 'red'},
{item: 'pen', madeIn: 'China', color: 'white'}
]
the output array that i want to produce :
outputArray = [
{item: 'pen', madeIn: 'US', color: ['blue', 'white']},
{item: 'pen', madeIn: 'China', color: ['red', 'white']}
];
I have been trying but no luck, the only solution that i can think of at the moment is that using a temporary variable to store the item and madeIn value. and the run another loop to compare item and madeIn and then add color to an array. There is several loop to solve this problem.
I mean it does the work, but definitely not an optimal solution. any other ideal will be welcome. Thank you.