How to use JavaScript Array map()
Array map
On this page
Array map() method
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
- Declare two variables a and b
- Initialize two variables a and b with value of array a = [1, 3, 5, 8] and b = a.map(c => c ** 2)
- array map() method map all array elements with statement and creates a new array.
- The value of b variable is displayed with the help of console.log inbuilt function