Skip to content
the poor coder

array map arrow function

Poor Man
Published
Reading time
1 min read

The map() method of the JavaScript Array object creates a new array by calling a function on every element in the original array. This new array is then returned. The function called is known as an arrow function.

An arrow function is a shorthand form of the traditional JavaScript function keyword. It takes the parameters of the function and returns the result of the expression. It has some advantages over the traditional function keyword, such as being less verbose and more efficient. The syntax looks like this:

JavaScript
const myFunction = (param1, param2) => {
  // code goes here
  return result; 
}

This shorthand version of an arrow function can be used in place of a traditional function when using the map() method. It is especially useful when you only need to perform a single operation on each element of the original array. For example, if you wanted to double each element in an array, you could use this arrow function:

JavaScript
const myArray = [1,2,3,4,5];
const newArray = myArray.map(x => x * 2);
// newArray is now [2,4,6,8,10]

As you can see, the arrow function is much more concise than a full function and easier to read. Using an arrow function with the map() method is a great way to quickly and efficiently modify an array.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC