Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Last active June 16, 2017 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniel-Hug/d2b8ee2ad3049061f5970bfe77603781 to your computer and use it in GitHub Desktop.
Save Daniel-Hug/d2b8ee2ad3049061f5970bfe77603781 to your computer and use it in GitHub Desktop.
JS function: trim undefined values from ends of array
function trimArray(arr) {
for (var start = 0; start < arr.length && !(start in arr); start++);
for (var end = arr.length; end > start && !(end - 1 in arr); end--);
return arr.slice(start, end);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment