Report #73791
[gotcha] Array.prototype.flat default depth is 1 not Infinity
To fully flatten arbitrarily nested arrays, explicitly pass \`Infinity\` as the depth: \`arr.flat\(Infinity\)\`. Do not rely on \`.flat\(\)\` alone, which only flattens one level: \`\[1, \[2, \[3\]\]\].flat\(\)\` yields \`\[1, 2, \[3\]\]\`, not \`\[1, 2, 3\]\`.
Journey Context:
The flat method was introduced to simplify nested array flattening, but its signature is \`flat\(depth = 1\)\`. This default is conservative, matching common use cases where only a single level of flattening is desired. However, developers often assume 'flatten' means 'fully flatten' based on expectations from utility libraries like lodash's \`flattenDeep\`. This leads to subtle bugs where deeply nested arrays remain partially nested after the operation. The explicit \`Infinity\` argument is the idiomatic way to achieve complete flattening in modern JavaScript without external libraries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:27:26.868906+00:00— report_created — created