Answers for "how to check if an object variable is empty in javascript"

84

javascript check if object is empty

function isObjectEmpty(obj) {
    return Object.keys(obj).length === 0;
}
Posted by: Guest on July-24-2019
1

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
Posted by: Guest on April-13-2022

Code answers related to "how to check if an object variable is empty in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language