How is array map working without passing the parameter?

vikasr78
const arr2 = arr.map(double)

How this is working without me passing the array item? I need to pass a parameter to function double: something like double(item).

let arr = [1, 2, 3, 4, 5]

function double(x) {
  return x * 2
}

const arr2 = arr.map(double)

const arr3 = arr.map(item => double(item))

console.log("arr2= ", arr2)
console.log("arr3= ", arr3)

Output:

arr2 = [2, 4, 6, 8, 10]

arr3 = [2, 4, 6, 8, 10]
Marco Nisi

Please read the map documentation.

The map method pass 3 arguments to the provided callback: the current element, the index and the original array.

You'll find everything in the doc.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing parameter to method in array.map

Print values of an array without passing as a parameter

update a Array without duplicate Map based on a parameter

How to print the sum of a passing a int array as a parameter

Passing parameter to a function parameter is not working

Reverse Pinvoke: passing array length without an explicit function parameter for size

Call function for all array elements without passing item as parameter

How to .map() array inside array like parameter?

Chocolatey Passing array as a parameter

Passing array as parameter in a method

Passing array as a parameter in a function

Passing an array as a parameter in PowerShell

Passing array in as parameter in C

Passing an Array of Collections as a Parameter

passing an parameter to an array of objects

Passing an array as a parameter in C

spring how to instantiate an @Autowired constructor without passing the parameter

How can I use variables without passing them as a parameter?

How can you call a void function in Flutter without passing a parameter?

Passing an array to .map() errors

Automapper: passing parameter to Map method

Java: Passing a Map as a function parameter

How to Pass Parameter to array.map()?

Passing a named parameter not working in boost

How can I update an associative array inside a function passing it by parameter?

How to map over an Spark array without exploding it?

How to Field Array with Map passing a Dynamic set of Fields

How to draw polyline on google map in android passing json array?

how array is working without declare it in this program