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

js: How to filter object keys from an array of objects?

I have an array similar to this one

let array = [
  {
    name: "1-name",
    age: 18,
    direction: "jsjs"
    phone: 7182718
  },
  {
    name: "2-name",
    age: 38,
    direction: "jsjsjs"
  },
  {
    name: "3-name",
    age: 58,
    direction: "jsjsjsjs"
  }
]

and i want to filter it based on its keys to get an array like this

[
  {
    name: "1-name",
    direction: "jsjs"
  },
  {
    name: "2-name",
    direction: "jsjsjs"
  },
  {
    name: "3-name",
    direction: "jsjsjsjs"
  }
]

Can you please help me i’ve try to solve it with no success

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 Try This Code:

let newArr = [];

array.forEach((e) => {
  newArr.push({ name: e.name, direction: e.direction });
});
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