lundi 25 septembre 2017

Find the value of an object in an array

I'm sure this is really easy but can someone help me to find the value of a object within an array so I can complete the IF statement?

Thanks for help in advance.

function renderHTML(data) {
  for (i = 0; i < 2; i++) {
    if ((data.reviews[i].rating).length == 1) {
      Do something.
    } else {
      Or do this something.
    }
  }
}

Here is the data I'm accessing:

{
"reviews": [
    {
        "rating": "5",
        "comments": "What a Great Company",
        "date": "1 hour ago",
        "reviewer": {
            "first_name": "Angela",
            "last_name": "F",
            "verified_buyer": "yes",
        },
        "ratings": [
            {
                "name": "Customer Service",
                "score": "5"
            }
        ],
        "branch": {
            "name": "Leicester",
            "description": null,
            "image": null
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire