I have this array and I want to create new object with the keys and values.
const arr = [
{
name: 'ab',
key: '584577',
},
{
name: 'cd',
key: '344926',
},
{
name: 'ef',
key: '804816',
},
];
for(const item of arr) {
setNewObject({...newObject, [item.name]: item.key})
}
But results prints nothing. This is my expected result:
{
ab: 584577,
cd: 344926,
ef: 804816
}
Here's a LIVE DEMO Can anyone point me in the right direction? Thanks in advance!