vendredi 25 août 2017

Check if object property value is false

I can't seem to find the explanation of how to check if a property value in an object is false. I have this code where I try to check if property 'active' is false but only the typeof data[i].active ==='undefined part works.

function createHTML(data) {
var myTable = document.getElementById('list');    
for(var i=0; i<data.length; i++) {
    var row = myTable.insertRow();
    for (var key in data[i]) {                
            var cell = row.insertCell();                
            if (data[i].hasOwnProperty(key) ) {                    
                cell.innerHTML = data[i][key];                    
                    if(typeof data[i].active === false || typeof 
                       data[i].active ==='undefined')  {
                        cell.innerHTML+= "<span class='eye'><i class='fa fa-
                        eye-slash'></i></span>";                             
                    } 
                }
            }  
        }

Aucun commentaire:

Enregistrer un commentaire