Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including deep-empty with all npm packages installed. Try it out:

var deepEmpty = require("deep-empty")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

deep-empty v0.1.5

deep-empty Build Status

This method does a depth first removal of "empty" values ( [], {}, '') from collections (arrays & objects).

For example, it will return an empty object for the following:

require('deep-empty')({ key : [ '', { foo: {}, bar: [] } ] })      => {}

It will return [false] for the following:

require('deep-empty')([[], false, {}])                             => [ false ]

The method can optionally be customized in two ways.

  1. You can pass in the values to keep when iterating over a collection.
  2. You can pass in the things that should not be considered a collection to iterate over.
deepEmpty(object[, toKeep[, toSkip]])

The defaults for the two methods above are:

function toKeep(value) {
    return  (_.isDate(value) || _.isFunction(value)) ||     // all dates and functions are kept
            (!_.isObject(value) && !_.isString(value)) ||   // all things that are not object or string are kep
            !_.isEmpty(value);                              // only non empty strings and objects are kept

function toSkip(value) {
    return !_.isObject(value) || _.isDate(value) || _.isFunction(value);


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free