Is there an ES6 way to easily filter out unwanted columns? Assume we have the following data:
const foo = [
{
a:'blah',
b:'blah',
c:'blah',
d:[
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
//... N number of objects
],
},
{
a:'blah',
b:'blah',
c:'blah',
d:[
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
{ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah'},
//... N number of objects
],
},
//... N number of objects
];
I would like to filter out the e and f values so I only have the following:
[
{
a:'blah',
b:'blah',
c:'blah',
d:[
{ a:'blah', b:'blah', c:'blah' },
{ a:'blah', b:'blah', c:'blah' },
{ a:'blah', b:'blah', c:'blah' },
//... N number of objects
],
},
{
a:'blah',
b:'blah',
c:'blah',
d:[
{ a:'blah', b:'blah', c:'blah' },
{ a:'blah', b:'blah', c:'blah' },
{ a:'blah', b:'blah', c:'blah' },
//... N number of objects
],
},
//... N number of objects
]
I figured it might be something similar to this, though I'm not sure how to handle the d value:
.map(x=>{ return {a: x.a, b: x.b, c: x.c, d:x.d}})
EDIT: Is there a way to do it without referencing the unwanted values (e or f)? In other words, only by referencing the values you want to keep (a,b,c,d)
d:[ {a:'blah', b:'blah', c:'blah', e:'blah', f:'blah' } ]instead of thisd:[ a:'blah', b:'blah', c:'blah', e:'blah', f:'blah' ]