Cannot read property 'length' of undefined despite check for undefined












-2














I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:



render() {
var metadata = this.props.data["metadata"]

if(typeof metadata !== undefined && metadata.length !== undefined) {

for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}

}

}


The render method is inside a component, which is placed inside another, by doing



<Marksheet data={this.state.data} />


I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.










share|improve this question




















  • 2




    !== 'undefined' -> !== undefined
    – ic3b3rg
    Dec 28 '18 at 0:03






  • 1




    You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
    – LGSon
    Dec 28 '18 at 0:04












  • also, can be simplified to if (metadata && metadata.length) { ... }
    – ic3b3rg
    Dec 28 '18 at 0:05










  • @LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
    – Charlie Fish
    Dec 28 '18 at 0:05






  • 1




    @LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
    – CertainPerformance
    Dec 28 '18 at 0:08
















-2














I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:



render() {
var metadata = this.props.data["metadata"]

if(typeof metadata !== undefined && metadata.length !== undefined) {

for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}

}

}


The render method is inside a component, which is placed inside another, by doing



<Marksheet data={this.state.data} />


I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.










share|improve this question




















  • 2




    !== 'undefined' -> !== undefined
    – ic3b3rg
    Dec 28 '18 at 0:03






  • 1




    You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
    – LGSon
    Dec 28 '18 at 0:04












  • also, can be simplified to if (metadata && metadata.length) { ... }
    – ic3b3rg
    Dec 28 '18 at 0:05










  • @LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
    – Charlie Fish
    Dec 28 '18 at 0:05






  • 1




    @LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
    – CertainPerformance
    Dec 28 '18 at 0:08














-2












-2








-2







I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:



render() {
var metadata = this.props.data["metadata"]

if(typeof metadata !== undefined && metadata.length !== undefined) {

for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}

}

}


The render method is inside a component, which is placed inside another, by doing



<Marksheet data={this.state.data} />


I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.










share|improve this question















I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:



render() {
var metadata = this.props.data["metadata"]

if(typeof metadata !== undefined && metadata.length !== undefined) {

for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}

}

}


The render method is inside a component, which is placed inside another, by doing



<Marksheet data={this.state.data} />


I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.







javascript reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 0:17

























asked Dec 28 '18 at 0:01









Ray A.

838




838








  • 2




    !== 'undefined' -> !== undefined
    – ic3b3rg
    Dec 28 '18 at 0:03






  • 1




    You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
    – LGSon
    Dec 28 '18 at 0:04












  • also, can be simplified to if (metadata && metadata.length) { ... }
    – ic3b3rg
    Dec 28 '18 at 0:05










  • @LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
    – Charlie Fish
    Dec 28 '18 at 0:05






  • 1




    @LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
    – CertainPerformance
    Dec 28 '18 at 0:08














  • 2




    !== 'undefined' -> !== undefined
    – ic3b3rg
    Dec 28 '18 at 0:03






  • 1




    You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
    – LGSon
    Dec 28 '18 at 0:04












  • also, can be simplified to if (metadata && metadata.length) { ... }
    – ic3b3rg
    Dec 28 '18 at 0:05










  • @LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
    – Charlie Fish
    Dec 28 '18 at 0:05






  • 1




    @LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
    – CertainPerformance
    Dec 28 '18 at 0:08








2




2




!== 'undefined' -> !== undefined
– ic3b3rg
Dec 28 '18 at 0:03




!== 'undefined' -> !== undefined
– ic3b3rg
Dec 28 '18 at 0:03




1




1




You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
– LGSon
Dec 28 '18 at 0:04






You have a space in metadata .length, just before the dot ... was that a copy-paste mistake?
– LGSon
Dec 28 '18 at 0:04














also, can be simplified to if (metadata && metadata.length) { ... }
– ic3b3rg
Dec 28 '18 at 0:05




also, can be simplified to if (metadata && metadata.length) { ... }
– ic3b3rg
Dec 28 '18 at 0:05












@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05




@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05




1




1




@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08




@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08












3 Answers
3






active

oldest

votes


















3














You could also use the Array.isArray method:



render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}





share|improve this answer

















  • 1




    This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
    – Hemadri Dasari
    Dec 28 '18 at 3:26












  • I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
    – Ray A.
    Dec 28 '18 at 7:33










  • That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
    – quirimmo
    Dec 28 '18 at 7:43










  • You're right. Looks like another part of the code was giving the same error
    – Ray A.
    Dec 29 '18 at 21:24



















2














The string "undefined" is not the same as undefined.



Try changing your code to the following:



render() {
var metadata = this.props.data["metadata"]

if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}


That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.






share|improve this answer





















  • Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
    – Ray A.
    Dec 28 '18 at 0:06










  • @RayA. Of course! Can you try printing what metadata is equal to?
    – Charlie Fish
    Dec 28 '18 at 0:07










  • Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
    – Ray A.
    Dec 28 '18 at 0:12










  • @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
    – Charlie Fish
    Dec 28 '18 at 0:13










  • I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
    – Ray A.
    Dec 28 '18 at 0:15



















1














Or just simply. You might also check for metadata.length >0 (instead of just length)



render() {
var metadata = this.props.data["metadata"]

if(metadata && metadata.length) {

for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}

}

}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952201%2fcannot-read-property-length-of-undefined-despite-check-for-undefined%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You could also use the Array.isArray method:



    render() {
    var metadata = this.props.data["metadata"];
    if(Array.isArray(metadata)) {
    metadata.forEach(val => console.log(val));
    }
    }





    share|improve this answer

















    • 1




      This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
      – Hemadri Dasari
      Dec 28 '18 at 3:26












    • I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
      – Ray A.
      Dec 28 '18 at 7:33










    • That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
      – quirimmo
      Dec 28 '18 at 7:43










    • You're right. Looks like another part of the code was giving the same error
      – Ray A.
      Dec 29 '18 at 21:24
















    3














    You could also use the Array.isArray method:



    render() {
    var metadata = this.props.data["metadata"];
    if(Array.isArray(metadata)) {
    metadata.forEach(val => console.log(val));
    }
    }





    share|improve this answer

















    • 1




      This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
      – Hemadri Dasari
      Dec 28 '18 at 3:26












    • I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
      – Ray A.
      Dec 28 '18 at 7:33










    • That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
      – quirimmo
      Dec 28 '18 at 7:43










    • You're right. Looks like another part of the code was giving the same error
      – Ray A.
      Dec 29 '18 at 21:24














    3












    3








    3






    You could also use the Array.isArray method:



    render() {
    var metadata = this.props.data["metadata"];
    if(Array.isArray(metadata)) {
    metadata.forEach(val => console.log(val));
    }
    }





    share|improve this answer












    You could also use the Array.isArray method:



    render() {
    var metadata = this.props.data["metadata"];
    if(Array.isArray(metadata)) {
    metadata.forEach(val => console.log(val));
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 28 '18 at 0:32









    quirimmo

    6,03111129




    6,03111129








    • 1




      This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
      – Hemadri Dasari
      Dec 28 '18 at 3:26












    • I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
      – Ray A.
      Dec 28 '18 at 7:33










    • That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
      – quirimmo
      Dec 28 '18 at 7:43










    • You're right. Looks like another part of the code was giving the same error
      – Ray A.
      Dec 29 '18 at 21:24














    • 1




      This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
      – Hemadri Dasari
      Dec 28 '18 at 3:26












    • I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
      – Ray A.
      Dec 28 '18 at 7:33










    • That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
      – quirimmo
      Dec 28 '18 at 7:43










    • You're right. Looks like another part of the code was giving the same error
      – Ray A.
      Dec 29 '18 at 21:24








    1




    1




    This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
    – Hemadri Dasari
    Dec 28 '18 at 3:26






    This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
    – Hemadri Dasari
    Dec 28 '18 at 3:26














    I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
    – Ray A.
    Dec 28 '18 at 7:33




    I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
    – Ray A.
    Dec 28 '18 at 7:33












    That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
    – quirimmo
    Dec 28 '18 at 7:43




    That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
    – quirimmo
    Dec 28 '18 at 7:43












    You're right. Looks like another part of the code was giving the same error
    – Ray A.
    Dec 29 '18 at 21:24




    You're right. Looks like another part of the code was giving the same error
    – Ray A.
    Dec 29 '18 at 21:24













    2














    The string "undefined" is not the same as undefined.



    Try changing your code to the following:



    render() {
    var metadata = this.props.data["metadata"]

    if(metadata !== undefined && metadata.length !== undefined) {
    for(var i=0; i<metadata.length; i++) {
    console.log(metadata[i]);
    }
    }
    }


    That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.






    share|improve this answer





















    • Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
      – Ray A.
      Dec 28 '18 at 0:06










    • @RayA. Of course! Can you try printing what metadata is equal to?
      – Charlie Fish
      Dec 28 '18 at 0:07










    • Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
      – Ray A.
      Dec 28 '18 at 0:12










    • @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
      – Charlie Fish
      Dec 28 '18 at 0:13










    • I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
      – Ray A.
      Dec 28 '18 at 0:15
















    2














    The string "undefined" is not the same as undefined.



    Try changing your code to the following:



    render() {
    var metadata = this.props.data["metadata"]

    if(metadata !== undefined && metadata.length !== undefined) {
    for(var i=0; i<metadata.length; i++) {
    console.log(metadata[i]);
    }
    }
    }


    That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.






    share|improve this answer





















    • Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
      – Ray A.
      Dec 28 '18 at 0:06










    • @RayA. Of course! Can you try printing what metadata is equal to?
      – Charlie Fish
      Dec 28 '18 at 0:07










    • Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
      – Ray A.
      Dec 28 '18 at 0:12










    • @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
      – Charlie Fish
      Dec 28 '18 at 0:13










    • I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
      – Ray A.
      Dec 28 '18 at 0:15














    2












    2








    2






    The string "undefined" is not the same as undefined.



    Try changing your code to the following:



    render() {
    var metadata = this.props.data["metadata"]

    if(metadata !== undefined && metadata.length !== undefined) {
    for(var i=0; i<metadata.length; i++) {
    console.log(metadata[i]);
    }
    }
    }


    That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.






    share|improve this answer












    The string "undefined" is not the same as undefined.



    Try changing your code to the following:



    render() {
    var metadata = this.props.data["metadata"]

    if(metadata !== undefined && metadata.length !== undefined) {
    for(var i=0; i<metadata.length; i++) {
    console.log(metadata[i]);
    }
    }
    }


    That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 28 '18 at 0:04









    Charlie Fish

    5,43942971




    5,43942971












    • Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
      – Ray A.
      Dec 28 '18 at 0:06










    • @RayA. Of course! Can you try printing what metadata is equal to?
      – Charlie Fish
      Dec 28 '18 at 0:07










    • Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
      – Ray A.
      Dec 28 '18 at 0:12










    • @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
      – Charlie Fish
      Dec 28 '18 at 0:13










    • I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
      – Ray A.
      Dec 28 '18 at 0:15


















    • Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
      – Ray A.
      Dec 28 '18 at 0:06










    • @RayA. Of course! Can you try printing what metadata is equal to?
      – Charlie Fish
      Dec 28 '18 at 0:07










    • Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
      – Ray A.
      Dec 28 '18 at 0:12










    • @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
      – Charlie Fish
      Dec 28 '18 at 0:13










    • I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
      – Ray A.
      Dec 28 '18 at 0:15
















    Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
    – Ray A.
    Dec 28 '18 at 0:06




    Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
    – Ray A.
    Dec 28 '18 at 0:06












    @RayA. Of course! Can you try printing what metadata is equal to?
    – Charlie Fish
    Dec 28 '18 at 0:07




    @RayA. Of course! Can you try printing what metadata is equal to?
    – Charlie Fish
    Dec 28 '18 at 0:07












    Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
    – Ray A.
    Dec 28 '18 at 0:12




    Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
    – Ray A.
    Dec 28 '18 at 0:12












    @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
    – Charlie Fish
    Dec 28 '18 at 0:13




    @RayA. So then metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
    – Charlie Fish
    Dec 28 '18 at 0:13












    I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
    – Ray A.
    Dec 28 '18 at 0:15




    I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
    – Ray A.
    Dec 28 '18 at 0:15











    1














    Or just simply. You might also check for metadata.length >0 (instead of just length)



    render() {
    var metadata = this.props.data["metadata"]

    if(metadata && metadata.length) {

    for(var i=0; i<metadata.length; i++) {
    console.log(metadata[i]);
    }

    }

    }





    share|improve this answer


























      1














      Or just simply. You might also check for metadata.length >0 (instead of just length)



      render() {
      var metadata = this.props.data["metadata"]

      if(metadata && metadata.length) {

      for(var i=0; i<metadata.length; i++) {
      console.log(metadata[i]);
      }

      }

      }





      share|improve this answer
























        1












        1








        1






        Or just simply. You might also check for metadata.length >0 (instead of just length)



        render() {
        var metadata = this.props.data["metadata"]

        if(metadata && metadata.length) {

        for(var i=0; i<metadata.length; i++) {
        console.log(metadata[i]);
        }

        }

        }





        share|improve this answer












        Or just simply. You might also check for metadata.length >0 (instead of just length)



        render() {
        var metadata = this.props.data["metadata"]

        if(metadata && metadata.length) {

        for(var i=0; i<metadata.length; i++) {
        console.log(metadata[i]);
        }

        }

        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 28 '18 at 9:23









        Nicholas

        1,29811320




        1,29811320






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952201%2fcannot-read-property-length-of-undefined-despite-check-for-undefined%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'