I am running the code below in chrome's console. I would like filteredArr to contain 3 objects however I am getting the empty {} as a fourth. The idea is to filter through the flags array and return objects with key == true(or === true - not sure which one works) and the values of true keys append to filteredArr. Any help is appreciated!
var flags = [ { usa: ["red", "white", "blue"] }, null, { germany: ["red", "yellow", "black"] }, {}, { jamaica: ["green", "yellow", "black"] }, "", undefined];
var filteredArr = flags.filter(function(val) {
return !(val === "" || typeof val == "undefined" || val === null || typeof val == "null");
});
filteredArr;
typeof val == "null"can be removed sincetypeof null === "object".filter(function(val){return !!val && Object.keys(val).length})