Knowledgize

.flat(depth)

Flattens a nested array by the specified depth.

Examples:

let nestedArray = [1, [2, [3, [4, 5]]]]; let flatArray = nestedArray.flat(); console.log(flatArray); // [1, 2, [3, [4, 5]]]
let deeplyNestedArray = [1, [2, [3, [4, 5]]]]; let flatDeepArray = deeplyNestedArray.flat(2); console.log(flatDeepArray); // [1, 2, 3, [4, 5]]