What does console.log([1, [2, [3, [4]]]].flat(Infinity)); output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-63.js
1console.log([1,[2,[3,[4]]]].flat(Infinity));
Quirks
Answer & explanation
Console output
[ 1, 2, 3, 4 ]
Why
Array.prototype.flat() flattens one level by default, but passing a depth argument controls how many levels it descends. Using Infinity tells it to recurse through all nesting levels, fully flattening the deeply nested array into [1, 2, 3, 4]. This is the idiomatic way to completely flatten arbitrarily nested arrays.