I am filtering null values from an array of objects but receiving not a clean array as output
//returns ,cat,snake,dog,cat,snake
//var input1 = [{"dog":"35","cat":"21","girrafe":"33","snake":"44"},{"dog":"22","cat":"","girrafe":"2","snake":""},{"dog":"","cat":"","girrafe":"88","snake":""}];
//returns ",,dog,girrafe,snake"
//var input1 = [{"dog":"43","cat":"32","girrafe":"1","snake":"33"},{"dog":"1","cat":"23","girrafe":"1","snake":"23"},{"dog":"","cat":"5","girrafe":"","snake":""}];
//returns dog,,dog,cat,snake
//var input1 = [{"dog":"","cat":"s","girrafe":"1","snake":"54"},{"dog":"x","cat":"y","girrafe":"45","snake":"x"},{"dog":"","cat":"","girrafe":"1","snake":""}];
//tried to fix with .join() but then
//returns doggirrafecat,girrafe if I uses console.log(input1.join())
var input1 = [{"dog":"","cat":"s","girrafe":"1","snake":"54"},{"dog":"x","cat":"y","girrafe":"","snake":"x"},{"dog":"s","cat":"","girrafe":"","snake":"ss"}];
//returns typeof object
var emptyKeys = input1.map(function (object) {
return Object.keys(object).filter(function (key) {
return object[key] === '';
});
});
console.log(emptyKeys)
So my goal is to get empty values in array of objects and get their keys. What am I doing wrong here and how do I fix it so that all inputs are return correctly?
Flattening the array solved it,
Thanks for the suggestions!!