'TypeError: Cannot read properties of undefined. NodeJS. Instagram Api

JSON Object structure

Error

I have very difficult to resolve error. I dont know why i cant reach my value. It parsing right. I am working on nodeJs and thats my code:

for(let i = 0; i < 60; i++) {
            if (tag.hashtag.edge_hashtag_to_media.edges[i].node === undefined) {
                continue;
            }
            let $this2 = tag.hashtag.edge_hashtag_to_media.edges[i].node;
            let url = $this2.display_url;
            let id = $this2.id;

Thanks for help :)



Solution 1:[1]

Perharps node property does not exist in edge[i] object so try this:

if ( ! tag.hashtag.edge_hashtag_to_media.edges[i].hasOwnProperty(node)) {
    continue;
}

this test check if node property exists

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alaindeseine