If i have an arr like the following
const myArray = [
{
key: 'blah',
value: 'Blah Blah'
},
{
key: 'foo',
value: 'Foos'
}
];
how I can get from it the following only using js
[
{
key: 'blah'
},
{
key: 'foo'
}
];
>Solution :
You can map the array to achieve this, like shown below:
const myArray = [{
key: 'blah',
value: 'Blah Blah'
},
{
key: 'foo',
value: 'Foos'
}
];
const result = myArray.map((item) => {
return {
key: item.key
}
})
console.log(result)