我希望能够从我的数组中删除空字符串。
这是我的数组:
let array = [{name:'John',age:'18',address:''},{name:'George',age:'',address:''},{name:'Kevin',age:'25',address:''}]
我希望仅在所有对象中的值为空时删除空字符串值。
期望结果:
[{name:'John',age:'18'},{name:'George',age:''},{name:'Kevin',age:'25'}]
这是我的做法,但它会移除所有的空字符串:
for (let i = 0; i < array.length; i++) {
array[i] = Object.fromEntries(Object.entries(array[i]).filter(([_, v]) => v != ''));
}
提前感谢您,