Created
January 16, 2024 07:48
-
-
Save Nalini1998/97ad6cee9a25181cf380c5439de54b1f to your computer and use it in GitHub Desktop.
The map() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The map() method is used to iterate over an array and modify its elements using a callback function. This callback function will run on each array element and return a new array of modified elements. | |
``` | |
// Syntax | |
myArray.map(callbackFn) | |
myArray.map(function(element, index, array){ /* ... */ }) | |
``` | |
For example: | |
``` | |
let salaries = [100, 300, 500]; | |
let salary = salaries.map(x => x * 2); | |
console.log(salary); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment