how can I not release data if two attributes are empty?
const fork = [
{ from: 'client', msg: null, for: null },
{ from: 'client', msg: '2222222222222', for: null },
{ from: 'server', msg: 'wqqqqqqqqqqqq', for: 'data/64.....' }
];
console.log(message)
These are three sample entries, in fact they are always replenished. And there are more.
I need to do this, if two attributes are empty then do not send if somewhere null then do not release this value
const fork = [
{ from: 'client', msg: null, for: null }, // remove line full
{ from: 'client', msg: '2222222222222', for: null }, // remove for
{ from: 'server', msg: null, for: 'data/64.....' } // remove msg
];
console.log(message)
>Solution :
const fork = [
{ from: 'client', msg: null, for: null },
{ from: 'client', msg: '2222222222222', for: null },
{ from: 'server', msg: 'wqqqqqqqqqqqq', for: 'data/64.....' }
];
const result = fork.map(item => {
if (Object.values(item).filter(i => i === null).length > 1) return null
const obj = {...item}
for (const key in obj) {
if (obj[key] === null) {
delete obj[key]
}
}
return obj
}).filter(item => item !== null)
console.log(result)