Interview Question

What is map()?

map transforms array elements into a new array.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

map creates a new array from callback results for each present element. • The returned array has the same length as the source array. • The original array is not replaced by map itself. • Empty slots remain empty in the result.

Example

Code
console.log([1, 2, 3].map(value => value * 2));
Output
[2, 4, 6]

Quick Revision

map transforms array elements into a new array.