I'm trying to extract specific value from JSON object using the following code:
data: any[] = [
{'id': 1, 'expenseType': {'id': 1, 'name': 'type1'} , 'cost': 100},
{'id': 2, 'expenseType': {'id': 2, 'name': 'type2'}, 'cost': 200 },
{'id': 3, 'expenseType': {'id': 3, 'name': 'type3'}, 'cost': 300} }
];
filterData = this.data.map(({ expenseType }) => ({
expenseType
}));
I want the filterData
to be an array of:
[{'id': 1, 'name': 'type1'},{'id': 2, 'name': 'type2'}, {'id': 3, 'name': 'type3']
The problem is that the key is also included.
Can I achieve this using array.map()
?