Skip to content

Commit 7810899

Browse files
authored
Did you know you can flat an array
1 parent b5f909a commit 7810899

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,19 @@ const nonMuatatedArray = ['a','b','c','d','e'];
119119
const newArray = nonMuatatedArray.filter((item'index) => !( index === 2 ));
120120
console.log(newArray) //['a','b','d','e']
121121
```
122+
123+
# Did you know you can flat an array?
124+
125+
```javascript
126+
const myArray = [2, 3, [4, 5],[7,7, [8, 9, [1, 1]]]];
127+
128+
myArray.flat() // [2, 3, 4, 5 ,7,7, [8, 9, [1, 1]]]
129+
130+
myArray.flat(1) // [2, 3, 4, 5 ,7,7, [8, 9, [1, 1]]]
131+
132+
myArray.flat(2) // [2, 3, 4, 5 ,7,7, 8, 9, [1, 1]]
133+
134+
//if you dont know the depth of the array you can use infinity
135+
myArray.flat(infinity) // [2, 3, 4, 5 ,7,7, 8, 9, 1, 1];
136+
137+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy