JavaScript

June 6, 2023

How to use JavaScript Array map()

Program to use JavaScript Array map() method


let a = [1, 3, 5, 8];
let b = a.map(c => c ** 2);

console.log(b);

Output


[ 1, 9, 25, 64 ]

Steps Description

  1. Declare two variables a and b
  2. Initialize two variables a and b with value of array a = [1, 3, 5, 8] and b = a.map(c => c ** 2)
  3. array map() method map all array elements with statement and creates a new array.
  4. The value of b variable is displayed with the help of console.log inbuilt function

by : Suhel Akhtar

Quick Summary:

JavaScript Array map() method