Skip to content

Commit

Permalink
Added flat method (ES10)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivarajnaidu authored Feb 21, 2019
1 parent 50acfd8 commit 1ef315d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ console.log(myNewArray4);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
```

### Solution 5: Using [`flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) in ES10

```js
var myNewArray5 = myArray.flat();
console.log(myNewArray5);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
```

Take a look [here](https://jsbin.com/janana/edit?js,console) these 4 algorithms in action.

For infinitely nested array try Lodash [flattenDeep()](https://lodash.com/docs#flattenDeep).
Expand Down

0 comments on commit 1ef315d

Please sign in to comment.