There is an array of objects, how to check if objects have empty values? An array of this type:

var data = [ { "test1": "", "test2": "2", }, { "test1": "1", "test2": "2", }, { "test1": "1", "test2": "", } ]; 

Actually, you need to output "2" to the console, i.e. in the array among all objects there are 2 empty values

    1 answer 1

     var data = [ { "test1": "", "test2": "2", }, { "test1": "1", "test2": "2", }, { "test1": "1", "test2": "", } ]; let count_null = 0; for(let val of data){ for(let key in val){ if(!val[key]){ console.log(`${key} - пусто`); count_null++; } } } console.log(`Пустых занчений ${count_null}`); 

    • With this implementation, { "test1": "1", "test2": 0, } will also be considered empty. Yes, and { "test1": "1", "test2": false, } also, which is not good. - Stepan Kasyanenko