I want to receive a single object array and return only the non-null values in the object arrays.
However, the method I have implemented contains non-null properties in an array and returns them as an array. How can I make it easier?
I want it to be returned as an object, not as an array.
const arr = [{
text01 : 'name',
text02 : 'email@gmail.com',
text03 : '010-1234-5678',
text04 : 'adress1',
text05 : 'adress2',
text06 : null,
text07 : null,
text08 : null,
},
{
text01 : 'name1',
text02 : 'email2@gmail.com',
text03 : '010-1255-5148',
text04 : 'adress3',
text05 : 'adress4',
text06 : null,
text07 : null,
text08 : null,
}]
getDataArr(arr) {
arr.forEach(item => {
const aaa = [];
for (let key in item) {
if (item[key] !== null) {
const value = item[key];
aaa.push({ key, value });
}
}
console.log(aaa);
});
// Get the value as const arr = [{
text01 : 'name',
text02 : 'email@gmail.com',
text03 : '010-1234-5678',
text04 : 'adress1',
text05 : 'adress2',
},
{
text01 : 'name1',
text02 : 'email2@gmail.com',
text03 : '010-1255-5148',
text04 : 'adress3',
text05 : 'adress4',
}]
},