Skip to content

Instantly share code, notes, and snippets.

@NiallJoeMaher
Created May 9, 2019 20:53
Show Gist options
  • Save NiallJoeMaher/2dc4705486039d4f1c3cb52b812fe90b to your computer and use it in GitHub Desktop.
Save NiallJoeMaher/2dc4705486039d4f1c3cb52b812fe90b to your computer and use it in GitHub Desktop.
// The simple one :P
const testArray1 = [1, 2, [3, 4]];
testArray1.flat(); // returns [1, 2, 3, 4]
const testArray2 = [1, 2, [3, 4, [5, 6]]];
testArray2.flat();
// returns [1, 2, 3, 4, [5, 6]];
testArray2.flat(2); // goes two levels deep recursively as we passed the parameter
// returns [1, 2, 3, 4, 5, 6];
const testArray3 = [1, 2, , 3, 4];
testArray3.flat();
// returns [1, 2, 3, 4];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment