I have an object that looks like this:
let Object1 = { id1: { date: '23-01-2023', status: 'completed' }, id2: { date: '02-01-2023', status: 'pending' } }
How can I make a new object that has only every key of the object, but also the value of one of the keys on the nested object, like this:
let Object2 = { id1: 'completed', id2: 'pending' }
>Solution :
You can map over Object.entries, replacing each value with the status property of that nested object, then create a new object with Object.fromEntries.
let obj1 = { id1: { date: '23-01-2023', status: 'completed' }, id2: { date: '02-01-2023', status: 'pending' } }
let res = Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k, v.status]));
console.log(res);