I have a code what take the next array:
const arr = [
{
name:'',
age:55
},
{
name:'Bill',
age:''
},
]
..and i should take into account, if the key does not contains a value, i should output for that key, the value: no data;
At the end i shoul get something like this:
const arr = [
{
name:'no data',
age:55
},
{
name:'Bill',
age:'no data'
},
]
I made this:
const arr = [
{
name:'',
age:55
},
{
name:'Bill',
age:''
},
]
const func = (arr) => {
const myKeys = arr.map(k => Object.keys(k))
return arr.map((i, k1) => {
return myKeys[k1].reduce((acc,r )=> {
return {
[acc] : !i[r].toString().length ? 'no data' :i[r]
}
})
})
};
console.log(func(arr))
How to achieve what i described above?