Skip to content

flat
77 bytes

Flatten an array of arrays into a single dimension

Usage

Given an array that contains many arrays, return a new array where all items from the children are present at the top level.

import * as
import _
_
from 'radashi'
const
const gods: string[][]
gods
= [['ra', 'loki'], ['zeus']]
const
const flat: string[]
flat
=
import _
_
.
flat<string>(lists: readonly string[][]): string[]
export flat

Given an array of arrays, returns a single dimensional array with all items in it.

@seehttps://radashi.js.org/reference/array/flat

@example

flat([[1, 2], [[3], 4], [5]])
// [1, 2, [3], 4, 5]

@version12.1.0

flat
(
const gods: string[][]
gods
) // => [ra, loki, zeus]

Note, _.flat is not recursive and will not flatten children of children of children … of children. It will only flatten T[][] an array of arrays.