check if object is empty javascript
snippet in javascript

javascript check if object is empty

user8631

function isObjectEmpty(obj) {
    return Object.keys(obj).length === 0;
}

javascript check empty object

user2449

function isEmptyObject(obj) {
    return !Object.keys(obj).length;
}

check if object is empty javascript

user5200

const empty = {};
/* -------------------------
  Plain JS for Newer Browser
----------------------------*/
Object.keys(empty).length === 0 && empty.constructor === Object
// true
/* -------------------------
  Lodash for Older Browser
----------------------------*/
_.isEmpty(empty)
// true

js check if object is empty

user9045

> !!Object.keys(obj).length;

react native object is empty

user336

//when this.state.errors object is empty 
if (Object.keys(this.state.errors).length == 0) {
  this.props.updateUser(user);
  this.props.navigation.goBack();
}

javascript test for empty object

user8069

// because Object.entries(new Date()).length === 0;
// we have to do some additional check
Object.entries(obj).length === 0 && obj.constructor === Object