I try to filter values from the next:
const data = [
{
car: 'audi',
age: 2,
power: 200
},
{
car: 'bmw',
age: 32,
power: 100
},
{
car: 'mercedes',
age: 21,
power: 150
},
];
const getRes = (data, keyTxt) => {
return data.map(i => {
return {
[keyTxt]: (
Object.entries(i).filter(j => !'car'.includes(j))
)
}
})
};
console.log(getRes(data, 'age'));
I try to check if word car exists in Object.entries(), and if it exists to delete all arrays which include the word and to get something like this:
{
"age": [
[
"age",
2
],
[
"power",
200
]
]
},
{
"age": [
[
"age",
32
],
[
"power",
100
]
]
},
{
"age": [
[
"age",
21
],
[
"power",
150
]
]
}
What is wrong with my code and why the filter does no work? How to make this code to be able to get what i described above?