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

filtering keys that are not in object

How can I remove non ext objects? I want to take pictures, but there is a problem because some objects do not have a picture. I’m confused about filtering. Can it be done with reduce or filter?

{
  "posts": [
    {
      "filename": "1647706792183",
      "ext": ".png",
      "w": 300,
      "h": 450,
      "tn_w": 166,
      "tn_h": 250,
      "tim": 1664328637690788,
      "time": 1664328637,
      "md5": "Omk9VtmPOD1U38U1OOAP/w==",
      "fsize": 200271,
      "resto": 0,
      "country": "DK",
      "bumplimit": 0,
      "imagelimit": 0,
      "semantic_url": "f1-relentless-formula-one-general-all-smiles",
      "replies": 378,
      "images": 155,
      "unique_ips": 102,
      "tail_size": 50
    },
    {
      "now": "09/27/22(Tue)21:31:17",
      "name": "Anonymous",
      "resto": 123946553,
    }
  ]
}

>Solution :

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

You can use .filter to run a function that returns true/false for each item of your data.

const data = { posts: [ .... ] };

const postsWithExt = data.posts.filter(post => post.ext !== undefined);

If you want to filter falsy values for .ext then use

posts.filter(post => !post.ext)
``
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