Created
July 23, 2015 10:22
-
-
Save ihorkatkov/9cf0a03d1e47dada02e4 to your computer and use it in GitHub Desktop.
[JS] Функция, которая определяет пуст ли объект. Возвращает true, если в объекте нет свойств и false — если хоть одно свойство есть.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isEmpty(obj) { | |
var counter = 0; | |
for (var key in obj) { | |
counter++; | |
} | |
if (counter == 0) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} |
Можно еще упростить))
const isEmpty = obj => Object.keys(obj).length ? false : true
еще легче const isEmpty = (obj) => !Object.keys(obj).length;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Можно еще упростить))
`function isEmpty(obj) {
}`