Parsing Json data from Api GET

Hi All - Im looking into getting the JSON formatted data on the for loop and console.log it

The data from the json response is inside an array, and there is an object that contains the properties that I need to access.

Something like this:
Screen Shot 2021-02-13 at 12.17.27 AM

xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4) {
        let toBeFormated = xmlHttp.responseText;
        let formatted = JSON.parse(toBeFormated);
        //console.log(formatted.data);
        for (let i = 0; i < formatted.data.length; i++) {
            console.log(formatted.data.length[i]);
        }
    }
}

Any point me to the right direction? TY

Hey there,

is this a FCC lesson?
Is it required to use the old approach?
You could use fetch instead of xmlHttp.


So your array has (multiple) objects. You access them with their index.
Then you can read a specific property of the object with either dot notation (e.g. .id) or square brackets (e.g. ["id"]). There are lessons on FCC about this.

Hi - Its not from a lesson. I review the lesson for “Accessing Object Properties with Dot Notation” though.

In the lesson, i understand I can access the object properties calling the objectName.property (with the dot or the bracket). However, from the formatted json data that I got from XHR, i can’t seem to understand where is the array name or the proper way to access it.

Also, I think my loop approach is not correct. Looking at similar requests, I saw that the best way will be to loop thru the array, which makes sense. So this where I’m at.

Ok its working now. Looks like i didnt need .length[i]. Instead just:

console.log(formatted.data[i]);

Then im able to get the data inside the array on console.log.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.