Created
May 9, 2019 20:53
-
-
Save NiallJoeMaher/2dc4705486039d4f1c3cb52b812fe90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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