Syntax

JavaScript Map an Array Syntax

In JavaScript, map an array: creates a new array by transforming each item — nums.map((n) => n * 2)

Quick Answer

Syntax
nums.map((n) => n * 2)
JavaScriptSyntax

Map an Array

Code example
nums.map((n) => n * 2)

Creates a new array by transforming each item.

Learn More

How to map an array in JavaScript

  1. Open your JavaScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

JavaScript Map an Array Syntax

Use nums.map((n) => n * 2).

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for map an array?

Use this pattern: nums.map((n) => n * 2)

Can I copy this JavaScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this JavaScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify