Example 1 — Default Depth (1)
One call unwraps a single nesting level.
const nested = [1, [2, 3], 4];
console.log(nested.flat());
// [1, 2, 3, 4] How It Works
- Start nested.
[2, 3]is one level deep. - Default depth.
flat()meansflat(1). - Unwrap once. The inner array’s items move up beside
1and4. - New array. You get a fresh list;
nestedis unchanged.

