Map method in JavaScript
May 7, 2022
Concise explanation of map() method in Js
- Creates a new array.
- Iterates through an array.
- Runs a callback function for each element in the array.
- Adds the result of that callback function to the new array.
- Returns the new array.
Note: map() always returns a new array of the same length.
How does it work?
Note: learn more about callback function parameters here.
Examples:
- Triple the value of each element in the given array.
2. Return a new array with the square root of all the values of the given array.