Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if object is empty

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

check empty object

Object.keys(object).length === 0
Comment

check if object is empty javascript

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

check empty object

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

is check objet empty

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

PREVIOUS NEXT
Code Example
Javascript :: convert elements to array javascript 
Javascript :: what is the meanof using next in nodejs 
Javascript :: palindrome rearranging javascript 
Javascript :: jquery validation plugin google recaptcha 
Javascript :: js string contains 
Javascript :: how to add two attay into object in javascript 
Javascript :: currency convertor api in javascript 
Javascript :: how to hash with crypto Node.js 
Javascript :: how to limit input type max length 
Javascript :: joi validation compare two password 
Javascript :: angular access service in console 
Javascript :: how can i validate a password without regex in js 
Javascript :: express redirect 
Javascript :: disable a button in javascript 
Javascript :: import react icons 
Javascript :: call javascript function use array 
Javascript :: lodash remove element from list 
Javascript :: string contains character javascript 
Javascript :: jest writing test 
Javascript :: jquery check checkbox 
Javascript :: post data from api using jquery ajax 
Javascript :: jquery select2 how to make dont close after select 
Javascript :: js setinterval 
Javascript :: jquery noconflict 
Javascript :: create an array of numbers 
Javascript :: deploy react js heroku 
Javascript :: remove node modules command windows 
Javascript :: first letter of each word in a sentence to uppercase javascript 
Javascript :: user api testing 
Javascript :: vue dynamic route push with params 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =