Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i can get from an array with multiple object, same array but with only specific keys and values?

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'
    }
];

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading