Skip to content

Instantly share code, notes, and snippets.

View apassiondev's full-sized avatar
🏠
Working from home

Andrea Ho apassiondev

🏠
Working from home
  • Vietnam
View GitHub Profile
@apassiondev
apassiondev / is-object-empty.js
Created December 3, 2020 22:34
Check if a JavaScript object is empty
// Check if an object is empty
// Option #1
const checkOpt1 = (obj) => {
for(let prop in obj) {
if (obj.hasOwnProperty(prop))
return false
}
return true
}
/**
* @type: JavaScript
* @todo Find all methods of an object
*/
const listMethods = obj => Object.getOwnPropertyNames(obj).filter(
item => typeof obj[item] === 'function'
)
// example
const food = {