Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7810899

Browse files
authored
Did you know you can flat an array
1 parentb5f909a commit7810899

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
constnewArray=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)

[8]ページ先頭

©2009-2025 Movatter.jp