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
andb
- Initialize two variables
a
andb
with value of arraya = [1, 3, 5, 8]
andb = 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