Advertisement
Guest User

Untitled

a guest
May 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. // The simple one :P
  2. const testArray1 = [1, 2, [3, 4]];
  3. testArray1.flat(); // returns [1, 2, 3, 4]
  4.  
  5. const testArray2 = [1, 2, [3, 4, [5, 6]]];
  6. testArray2.flat();
  7. // returns [1, 2, 3, 4, [5, 6]];
  8. testArray2.flat(2); // goes two levels deep recursively as we passed the parameter
  9. // returns [1, 2, 3, 4, 5, 6];
  10.  
  11. const testArray3 = [1, 2, , 3, 4];
  12. testArray3.flat();
  13. // returns [1, 2, 3, 4];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement