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

check in mapping if contain null values in react js

here is the mapping which displaying the all the data i have to put check if body contains nulll then dont display them.any help would be apprecited

 {logs &&
            logs.map((log, value) => 
              Object.keys(log.body).map((key) => (  
                <tr key={key}>
                  <td>{key}</td>
                  <td>{JSON.stringify(log.body[key])}</td>
                </tr>
              ))
            )} 

And here is the API.

[
    {
        "id": 1,
        "body": {
            "buy_WBNB": 0.1231,
            "sell_WBNB": 0.1541, 
            "expected_profit": -42.27542384981283,  
        },
        "response": "CONNECTION ERROR: The connection got closed with the close code `4040`",
        "created_at": "Feb 28, 2022 11:57 AM"
    },
    {
        "id": 2011,
        "body": null,
        "response": "connection not open on send()",
        "created_at": "Feb 28, 2022 5:49 PM"
    }, 
]

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 :

check first log.body exist

{logs &&
    logs.map((log) =>
    log.body && Object.keys(log.body).map((key) => (
        <tr key={key}>
          <td>{key}</td>
          <td>{JSON.stringify(log.body[key])}</td>
        </tr>
      ))
    )}

output will look like:
enter image description here

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