Skip to content

Instantly share code, notes, and snippets.

@henvo
Created October 9, 2024 22:24
Show Gist options
  • Save henvo/38b517ab84f61b1cfe7f926b53e570c3 to your computer and use it in GitHub Desktop.
Save henvo/38b517ab84f61b1cfe7f926b53e570c3 to your computer and use it in GitHub Desktop.
Simple flatten function in JavaScript
const flatten = (input, ary = []) => {
if (!Array.isArray(input)) { return ary.push(input) };
input.forEach((v) => flatten(v, ary));
return ary;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment