Sitemap
Front-end World

JavaScript | TypeScript | React.js | Next.js | Vue.js | Angular | Analog | HTML | CSS | SASS | Tailwind CSS | Shadcn UI | TanStack | Turbopack | Vite | HTMX | RxJS | GraphQL | REST APIs | Node.js | Express.js | Nest.js | Docker | DevOps | Web Security & Web Accessibility

Complete Guide to JavaScript Map() Method 🚀

4 min readMar 9, 2025

--

Press enter or click to view image in full size
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]

--

--

devhonufa
devhonufa

Written by devhonufa

"devhonufa" is your go-to blog for easy-to-follow coding tutorials, tips, and tricks to help you learn and grow as a programmer

Front-end World
Front-end World

Published in Front-end World

JavaScript | TypeScript | React.js | Next.js | Vue.js | Angular | Analog | HTML | CSS | SASS | Tailwind CSS | Shadcn UI | TanStack | Turbopack | Vite | HTMX | RxJS | GraphQL | REST APIs | Node.js | Express.js | Nest.js | Docker | DevOps | Web Security & Web Accessibility