Member-only story
Complete Guide to JavaScript Map() Method 🚀
JavaScript map() — what is that?
map() method generates a new array using a function over each element in a given array. It leaves the original array unchanged.
Facts points:
🔹map() traverses over an array.
🔹It transforms every item based on a provided function.
🔹It delivers a new array (the array itself isn’t changed).
🔹It doesn’t invoke the function on absent slots in sparse arrays.
1. map() Syntax
const newArray = array.map((element, index, array) => {
return newValue;
});🔹element → The current array element being processed.
🔹index(optional) → The index of the current element.
🔹array (optional) → The originally mapped array.
🔹thisArg (optional) → A value to use as this when executing callbackFunction.
🔹Returns→ New array with values changed.
2. Basic Example
> Double a list of numbers:
const numbers = [1, 2, 3, 4, 5];
const doubledNumbers = numbers.map(num => num * 2);
console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10]







