- 123
The map function in JavaScript is a powerful method that allows you to create a new array by applying a function to each element of an existing array. This method is particularly useful for transforming data in a concise and readable manner.
Basic Usage
The map function takes a callback function as an argument. This callback function is executed for each element in the array, and its return value is added to the new array. Here is a simple example:
const numbers = [1, 2, 3, 4];const doubled = numbers.map(num => num * 2);console.log(doubled); // Output: [2, 4, 6, 8]In this example, the map function multiplies each element in the numbers array by 2 and returns a new array with the doubled values1.
Working with Objects
You can also use the map function to transform arrays of objects. For instance, if you have an array of objects representing people, you can use map to create an array of their full names:
JavaScript Array map() Method - W3Schools
map() creates a new array from calling a function for every array element. map() does not execute the function for empty elements. map() does not change the original array.
See results only from w3schools.comTry It Yourself
The W3Schools online code editor allows you to edit code and view the result in …
Tryit Editor V3.6
The W3Schools online code editor allows you to edit code and view the result in …
Array.prototype.map() - JavaScript | MDN - MDN Web Docs
- The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array.
JavaScript Array map() Method - GeeksforGeeks
Mar 12, 2025 · Example 1: Here, we are using the map () method to create a new array containing the square roots of each number in the original array. Example 2: This example uses the array …
- Estimated Reading Time: 3 mins
JavaScript Map Method – Syntax and Code Examples
Feb 15, 2024 · The map method iterates over each element of the array, applies the callback function, and returns a new array (uppercasedNames) containing the uppercase names. This …
JavaScript Array map() Method - JavaScript Tutorial
The JavaScript Array map() method creates a new array that includes the results by applying a function to every element in the original array. Here’s the syntax of the map() method: …
- Estimated Reading Time: 3 mins
JavaScript Map – How to Use the JS .map() Function …
Mar 31, 2021 · Instead of manually iterating over the array using a loop, you can simply use the built-in Array.map() method. The Array.map() method allows you to iterate over an array and modify its elements using a callback function. The …
- People also ask
JavaScript Map, Reduce, and Filter - JS Array Functions …
Nov 10, 2019 · Map, reduce, and filter are all array methods in JavaScript. Each one will iterate over an array and perform a transformation or computation. Each will return a new array based on the result of the function. In this article, you …
Examples of JavaScript's map function in real life - Shaile
Jan 6, 2021 · Without further ado, here are some examples of map in a real production environment. The map function is called on an array, and takes in one parameter: a callback. It performs this callback function on every element in …
JavaScript Array map() - Programiz
The map() method creates a new array with the results of calling a function for every array element. Example let numbers = [2, 4, 6, 8, 10]; // function to return the square of a number …
How to Use the JS .map() Function (Array Method) - ExpertBeacon
Aug 30, 2024 · The .map() method creates a new array doubledNumbers, with each number doubled from the original numbers array. This is just one simple example, but .map() can …
Related searches for JavaScript Array Map Function Examples
- Some results have been removed