Can someone please help me resolve below object in javascript? I would be so grateful for your help.
//Current Object:
Data: {
Name: [‘A’, ‘B’, ‘C’, ‘D’],
Id: [1, 2, 3, 4]
}
//Expected output:
Data: {
{Name: ‘A’, Id: 1},
{Name: ‘B’, Id: 2},
{Name: ‘C’, Id: 3},
{Name: ‘D’, Id: 4}
}
I have tried mapping it with Object.keys() and map() function, but it didn’t help much. I am a beginner at Javascript, looking for someone’s help.
2
Answers
You can’t create an object:
But instead of that you can make an array:
Example code:
You can use helper function with destructuring arguments and
.map()
like this: