Skip to content

Instantly share code, notes, and snippets.

@hkan
Last active August 29, 2015 14:02
Show Gist options
  • Save hkan/72e7b9b38f73254dfdbb to your computer and use it in GitHub Desktop.
Save hkan/72e7b9b38f73254dfdbb to your computer and use it in GitHub Desktop.
Filter Out Empty Strings of Array

Filter Empty Values

Returns a new array without the empty strings.

Usage

var myArray = [ "hakan", "", "0", 0, false ];

myArray = myArray.filterEmpty();

// it became this:
[ "hakan", "0", 0, false ]
Array.prototype.filterEmpty = function() {
this.filter(function(item) {
return item.length;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment