Skip to content

Instantly share code, notes, and snippets.

@xinglongjizi
Created May 16, 2024 03:46
Show Gist options
  • Select an option

  • Save xinglongjizi/307370ac53edd2a5a7b7e0403f5b87e8 to your computer and use it in GitHub Desktop.

Select an option

Save xinglongjizi/307370ac53edd2a5a7b7e0403f5b87e8 to your computer and use it in GitHub Desktop.
/**
*
* @desc 判断`obj`是否为空
* @param {Object} obj
* @return {Boolean}
*/
function isEmptyObject(obj) {
if (!obj || typeof obj !== 'object' || Array.isArray(obj))
return false
return !Object.keys(obj).length
}
module.exports = isEmptyObject
/*
因此判断是否是对象 {} 的方式可以是:
if (obj && typeof obj === 'object' && !Array.isArray(obj)) { }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment