Higher Order Functions

flatMap Maps Then Flattens

flatMap Maps Then Flattens

flatMap runs a mapping callback, then flattens one level of arrays from the result. It is useful when each source item can produce several output items.

Without flattening, you would get an array of arrays. With flatMap, downstream code receives one continuous list.

Your task: Use flatMap to create allTags from modules. The result should contain every tag from every module in module order.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

flatMap Maps Then Flattens

flatMap runs a mapping callback, then flattens one level of arrays from the result. It is useful when each source item can produce several output items.

Without flattening, you would get an array of arrays. With flatMap, downstream code receives one continuous list.

Your task: Use flatMap to create allTags from modules. The result should contain every tag from every module in module order.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.