Skip to content

Instantly share code, notes, and snippets.

@omarkdev
Created February 20, 2020 20:16
Show Gist options
  • Save omarkdev/842e343c41653729cc9bf02956de8ebf to your computer and use it in GitHub Desktop.
Save omarkdev/842e343c41653729cc9bf02956de8ebf to your computer and use it in GitHub Desktop.
const arr1 = ['a', ['b', ['c']], 1, [2, [3, [4, [5]]]]];
const arr1Flatted1 = arr1.flat();
// ["a", "b", Array(1), 1, 2, Array(2)]
const arr1Flatted2 = arr1.flat(2);
// ["a", "b", "c", 1, 2, 3, Array(2)]
const arr1FlattedInfinity = arr1.flat(Infinity);
// ["a", "b", "c", 1, 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment