'Array ouput says "undefined" in xhr request

My XHR Request works but after that I wanted to access the array's objects seperately.

When I just use ....<li> + comments[i] + </li>.... it perfectly displays my array but when I wanted to use certain objects within it returns "undefined".

<script>
window.onload = function(){   

const xhr = new XMLHttpRequest();


 
    xhr.onload = function (){
        
       
        if(xhr.status == 200){
            
           
           var comments = JSON.parse(this.responseText);
          
           let output = "";
           
           for(var i=0;i< comments.length; i++){
               output += '<ul>' +
               '<li>' + comments[i]['comment_user'] + '</li>' +
               '</ul>';
           }
           
            document.getElementById('comment_section').innerHTML = output;
                    
       }  
       
      }
      
      xhr.open('GET', 'inc/getcom.inc.php', true);
  
      xhr.send();  
    }
</script>

Thanks for help, i'm searching for hours now...



Sources

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

Source: Stack Overflow

Solution Source