/

Check if JavaScript object is empty

javascript
js
if (
Object.keys(changedFields).length !== 0 &&
changedFields.constructor === Object
) {
// do something
}

or use a function:

js
const isObjectEmpty = (obj) => {
return Object.keys(obj).length !== 0 && obj.constructor === Object
}
Edit this page
Want to make your own site like this?
Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Zander Martineau.