Skip to content

Instantly share code, notes, and snippets.

@lai32290
Last active May 19, 2016 02:11
Show Gist options
  • Save lai32290/10f4fcf9555212ee9911c8a15b3789a3 to your computer and use it in GitHub Desktop.
Save lai32290/10f4fcf9555212ee9911c8a15b3789a3 to your computer and use it in GitHub Desktop.
Array Flat
Array.prototype.flat = function () {
var result = [];
this.forEach(function (item) {
if (Array.isArray(item)) {
result = result.concat(item.flat());
return;
}
result.push(item);
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment