0

I'm working on an app that pulls data from an API I get a JSON object that looks like this:

[
  {
    "word": "run",
    "phonetics": [
      
    ],
    "meanings": [
      {
        ..
      },
      {
        "partOfSpeech": "noun",
        "definitions": [
          {
            "definition": "act or instance of running, of moving rapidly using the feet.",
            "synonyms": [
              
            ],
            "antonyms": [
              
            ],
            "example": "I just got back from my morning run."
          },
          {
            ..
          }
        ],
        "synonyms": [
          
        ],
        "antonyms": [
          
        ]
      },
      {
        ..
      },
      {
        ..
      }
    ],
    "license": {
      ..
    },
    "sourceUrls": [
      
    ]
  }
]

I've cut out the majority of the data that makes this too big to deal with but the main issue I'm having is every time there's a rerender I get different data which is what I want but sometimes the property that I'm looking for won't be there for example "audio" which is deeply nested in phonetics the problem I'm having is that I want to check if the property exists in the object before looking for it so I don't get an error of undefined

Dean Van Greunen
  • 5,060
  • 2
  • 14
  • 28
flowoverstack
  • 92
  • 1
  • 8
  • Does this answer your question? [How do I check if an object has a specific property in JavaScript?](https://stackoverflow.com/questions/135448/how-do-i-check-if-an-object-has-a-specific-property-in-javascript) – silencedogood Jul 22 '22 at 18:05
  • no every time use something like has own property it always returns false – flowoverstack Jul 22 '22 at 18:36
  • How about this one. [Checking for deeply nested properties in object](https://stackoverflow.com/questions/2631001/test-for-existence-of-nested-javascript-object-key) – silencedogood Jul 22 '22 at 18:38

0 Answers0