I need to check my java object value is empty or not. And I need to check this one by one. I crate my code to do this task...But I can't check values one by one. If all of my object value is empty, my code is working...But it can't check values one by one.
const coverDesc = action.data.coverDescriptionLocalization;
Methord 01- :-
if (Object.values(coverDesc ).every((x) => x === null || x === '')) {
console.log('Empty');
} else {
console.log('Not empty');
}
Methord 02- :-
for (const key in coverDesc) {
if (coverDesc.hasOwnProperty(key)) {
if (Object.values(coverDesc[key]).every((x) => x === null || x === '')) {
console.log('Empty');
} else {
console.log('Not empty');
}
}
}
If you just want to check whether there's a truthy value, you can do:
Object.keys(coverDesc).every((k) => coverDesc[k] === false)
If you need to check specifically for an empty string over null, I would think checking against "" is the best, using the === operator
Object.keys(coverDesc).every((k) => coverDesc[k] === false)