Check whether objects of keys as empty values or not based on boolean
If empty exits true || false:
Simple understanding:
if ((object of keys (schoolData) === ‘ ‘(is empty) ) {return true;}else {return false}
Program:
function checkObjectOfKeys(obj: any) : Boolean {
if (obj == null || obj === undefined || obj === ”) {
return true;
}
if (Array.isArray(obj)) {
if (obj.length === 0) {
return true;
}
}
if (typeof obj === ‘object’) {
for (const key in obj) {
if (this.checkObjectOfKeys(obj[key])) {
return true;
}
}
}
return false;
}
Input:
const schoolData= {
“student”: {
rank: 2,
name: ‘aswin’,
grade: ‘O’,
},
“subject”:[‘maths’, ‘science’, ‘social’],
“class”:{
“extra_curicullam”:[‘carrom’, ‘circket’],
“testType”:[‘unit-test’, ‘class-test’],
}
}
this.checkObjectOfKeys(schoolData);
// output: false;
Snap for reference: