ES6+beginner
Array.prototype Methods: flat, flatMap, includes
Three newer array methods that flatten nested arrays, combine mapping with flattening in one pass, and check for element presence without coercion quirks.
flat(), flatMap(), and includes() are relatively newer additions to Array.prototype that fill gaps the earlier array methods left, and while individually small, fluency with all three is expected in modern interviews.
flat() is like unpacking boxes containing smaller boxes onto one flat table. flatMap() does that unpacking while relabeling every item in one pass. includes() is a bouncer who recognizes a guest even with a smudged name badge (NaN), unlike an overly literal doorman (indexOf) who never matches a smudged badge.
Key Concepts
1
array.flat(depth) returns a new array with nested sub-arrays flattened up to the specified depth (defaulting to 1), recursively unwrapping arrays-within-arrays. It's the standard modern replacement for older manual recursive-flattening tricks.
2
array.flatMap(callback) combines map() and a single-level flat() into one pass: it applies callback to every element like map(), but if a callback returns an array, its elements are spliced directly into the result rather than nested — useful for transformations producing zero, one, or several output items per input item.
3
array.includes(value) checks whether an array contains a value, returning a boolean, using the SameValueZero algorithm rather than strict equality — the practical difference being includes correctly finds NaN in an array, whereas indexOf-based checks always fail since indexOf uses strict equality and NaN !== NaN.