MediumArray Methods💻 Output Question

flatMap — map then flatten one level

💡

Hint

flatMap = map + flat(1). Perfect when each element produces multiple values.

What does this output?

const sentences = ['hello world', 'foo bar'];
const words = sentences.flatMap(s => s.split(' '));
console.log(words.length);
console.log(words[1]);

Correct Output

4
world

Why this output?

Explanation: flatMap maps to arrays then flattens one level. ["hello","world"] + ["foo","bar"] → 4 words.

Key Insight: flatMap = map + flat(1). Perfect when each element produces multiple values.

More Array Methods Output Questions

Easymap transforms each elementMediumfilter then map chainMediumreduce accumulates to a single valueMediumfind returns first match; filter returns all

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz