June 5, 2023
Program to use JavaScript Array flatMap() method
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let b = a.flatMap((a) => a * 3);
console.log(b);
Output
[
3, 6, 9, 12, 15,
18, 21, 24, 27, 30
]
Steps Description
- Declare two variables
a
andb
- Initialize two variables
a
andb
with value of stringa = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
andb = a.flatMap((a) => a * 3)
Array flatMap()
method map all array elements and creates a new array.- The value of
b
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array flatMap() method