Lodash isEmpty
by findango
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
<script>
function stringify(value) {
return typeof value === 'object'
? JSON.stringify(value, null, 2)
: value;
}
function log() {
var args = Array.prototype.slice.call(arguments, 0);
document.getElementById('output').innerHTML += args.map(stringify).join(" ") + "\n";
}
</script>
<pre id="output"></pre>
JavaScript
const thing = 'not empty';
const nothing = null;
const nodef = undefined;
log(_.isEmpty(['a', 'b', 'c']));
log(_.isEmpty(thing));
log(_.isEmpty([]));
log(_.isEmpty());
log(_.isEmpty(nothing));
log(_.isEmpty(nodef));
const obj = { a: 'one', b: null, c: ['x', 'y', 'z'], d: []};
log(obj);
log(_.omitBy(obj, _.isEmpty));