Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Created May 13, 2015 14:01
Show Gist options
  • Save lotsofcode/ee21af5bd02c54a02d1a to your computer and use it in GitHub Desktop.
Save lotsofcode/ee21af5bd02c54a02d1a to your computer and use it in GitHub Desktop.
remove empty elements from array
// pre 1.6
function cleanArray(actual){
var newArray = new Array();
for(var i = 0; i<actual.length; i++){
if (actual[i]){
newArray.push(actual[i]);
}
}
return newArray;
}
// js 1.6+
arr = arr.filter(function(n){ return n != undefined });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment