Displaying List Of JavaScript Objects As HTML List Items

前端 未结 5 1061
野趣味
野趣味 2021-01-23 17:58

When I attempt this, the HMTL page only displays the last object, instead of all the objects.

Here is my JavaScript file

var family = {
  aaron: {
    n         


        
5条回答
  •  再見小時候
    2021-01-23 18:31

    Just you don't need to define function

    html file:

    var family = {
        aaron: {
            name: 'Aaron',
            age: 30
        },
        megan: {
            name: 'Megan',
            age: 40
        },
        aaliyah: {
            name: 'Aaliyah',
            age: 2
        }
    }
    
    for (var prop in family) {
    
        document.getElementById('aaron-family').innerHTML += '
  • ' + prop + '
  • '; }
    
        
            Aaron's Test With Objects
        
        
    
            

提交回复
热议问题