Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check if a javascript object is empty?

const emptyObject = {
}
// Using keys method of Object class
let isObjectEmpty = (object) => {
  return Object.keys(object).length === 0;
}
console.log(isObjectEmpty(emptyObject)); // true

// Using stringify metod of JSON class
isObjectEmpty = (object) => {
  return JSON.stringify(object) === "{}";
}
console.log(isObjectEmpty(emptyObject)); // true
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #check #javascript #object
ADD COMMENT
Topic
Name
5+9 =