React check if object is empty | How to check if an Object is Empty in React

Spread the love

React check if object is empty | How to check if an Object is Empty in React

let test = {

height:10,
weight:98

}

if (Object.keys(test).length == 0) {

//dosomething
}

else

{

//dosomething

}

2. Method

function isEmpty(obj) {
for (const property in obj) {
return false;
}
return true;
}

console.log(isEmpty({})); // true
console.log(isEmpty({id: 1, name: ‘Rob’})); // false

 

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *