Im using Angular8, want to remove empty object from an array, and get its length
Array: [
{data01: "abc", data02: "cde", data03: "fgh", data04: "", data05: ""},
{data01: "abc", data02: "cde", data03: "", data04: "", data05: ""},
{data01: "abc", data02: "cde", data03: "fgh", data04: "ijk", data05: "lmn"},
{data01: "abc", data02: "", data03: "", data04: "", data05: ""},
]
then I want it be like
Array: [
{data01: "abc", data02: "cde", data03: "fgh"},
{data01: "abc", data02: "cde"},
{data01: "abc", data02: "cde", data03: "fgh", data04: "ijk", data05: "lmn"},
{data01: "abc"},
]
is that anyway to do it ?
I tried to push those element in a new array like
_Array: ["abc","cde", "fgh", "", "", ....]
and chunk it by 5 then filter(Boolean), it works, but the performance was bit slow, any other way to improve the performance?
arr.map(i => Object.entries(i).filter(([k,v]) => v).reduce((acc,[k,v]) => ({...acc, [k]: v}), {}))