Javascript 在对对象数组使用map()时,我得到了奇怪的输出,如何修复它?

Javascript 在对对象数组使用map()时,我得到了奇怪的输出,如何修复它?,javascript,arrays,object,es5-compatiblity,Javascript,Arrays,Object,Es5 Compatiblity,我从一个对象数组中过滤空值,但没有收到一个干净的数组作为输出 //返回,猫,蛇,狗,猫,蛇 //变量input1=[{“狗”:“35”,“猫”:“21”,“吉拉夫”:“33”,“蛇”:“44”},{“狗”:“22”,“猫”:“吉拉夫”:“2”,“蛇”:“},{“狗”:“猫”:“吉拉夫”:“88”,“蛇”:“}”; //返回“、狗、女孩、蛇” //变量input1=[{“狗”:“43”,“猫”:“32”,“吉拉菲”:“1”,“蛇”:“33”},{“狗”:“1”,“猫”:“23”,“吉拉菲”:“1

我从一个对象数组中过滤空值,但没有收到一个干净的数组作为输出

//返回,猫,蛇,狗,猫,蛇
//变量input1=[{“狗”:“35”,“猫”:“21”,“吉拉夫”:“33”,“蛇”:“44”},{“狗”:“22”,“猫”:“吉拉夫”:“2”,“蛇”:“},{“狗”:“猫”:“吉拉夫”:“88”,“蛇”:“}”;
//返回“、狗、女孩、蛇”
//变量input1=[{“狗”:“43”,“猫”:“32”,“吉拉菲”:“1”,“蛇”:“33”},{“狗”:“1”,“猫”:“23”,“吉拉菲”:“1”,“蛇”:“23”},{“狗”:“猫”:“5”,“吉拉菲”:“蛇”:“5”);
//返回狗、狗、猫、蛇
//变量input1=[{“狗”:“猫”:“s”,“吉拉菲”:“1”,“蛇”:“54”},{“狗”:“x”,“猫”:“y”,“吉拉菲”:“45”,“蛇”:“x”},{“狗”:“猫”:“吉拉菲”:“1”,“蛇”:“}];
//试图用.join()进行修复,但是
//如果使用console.log(input1.join()),则返回doggirrafecat、girrafe
变量input1=[{“狗”:“,”猫”:“s”,“吉拉菲”:“1”,“蛇”:“54”},{“狗”:“x”,“猫”:“y”,“吉拉菲”:“蛇”:“x”},{“狗”:“s”,“猫”:“,”吉拉菲”:“蛇”:“ss”});
//返回对象的类型
var emptyKeys=input1.map(函数(对象){
返回对象。键(对象)。过滤器(函数(键){
返回对象[键]=='';
});
});

console.log(emptyKeys)
展平阵列解决了它

var flatArray=Array.prototype.concat.apply([],input1)

这就是你的意思吗?

我不知道你想做什么。是否要获取数组中的所有空
字符串
?是,获取对象数组中的空值并获取它们的keys@JohnLong你的预期产出是多少?这似乎很好,因为您的地图将为一个对象返回一个空数组,而该对象没有任何具有空值的键。@VLAZ是的,作为字符串,我想从这些输入返回的是最佳情况下的一个数组,但字符串也很好。太棒了。谢谢我使用了var flatArray=Array.prototype.concat.apply([],input1);因为我在ES5上,你能解释一下为什么这可以解决OPs问题吗?
input1.reduce(function(accumulator, currentValue){
    accumulator.push(...Object.entries(currentValue).filter((kvPair) => kvPair[1] === '').map(ele => ele[0]));
    return accumulator;
}, [])
input1.reduce(function(accumulator, currentValue){
    accumulator.push(...Object.entries(currentValue).filter((kvPair) => kvPair[1] === '').map(ele => ele[0]));
    return accumulator;
}, [])