Reputation: 49
i need to remove keys of the objects inside with another object using typescript.
let before = {
'0': {
'title':'title 1',
'time':'12.30pm',
},
'1': {
'title':'title 2',
'time':'12.30pm',
},
'2': {
'title':'title 3',
'time':'12.30pm',
},
}
expected results,
let after = [
{
'title':'title 1',
'time':'12.30pm',
},
{
'title':'title 2',
'time':'12.30pm',
},
{
'title':'title 3',
'time':'12.30pm',
}
]
Upvotes: 1
Views: 64
Reputation: 10975
To achieve expected result, use below option of using Object.entries
and map
let before = {
'0': {
'title':'title 1',
'time':'12.30pm',
},
'1': {
'title':'title 2',
'time':'12.30pm',
},
'2': {
'title':'title 3',
'time':'12.30pm',
},
}
console.log(Object.entries(before).map(v => v[1]))
Upvotes: 1
Reputation: 4488
Just use Object.values(before)
let before={0:{title:"title 1",time:"12.30pm"},1:{title:"title 2",time:"12.30pm"},2:{title:"title 3",time:"12.30pm"}};
console.log(Object.values(before));
Upvotes: 6