Skip to content

Instantly share code, notes, and snippets.

@Nalini1998
Created January 16, 2024 07:48
Show Gist options
  • Save Nalini1998/97ad6cee9a25181cf380c5439de54b1f to your computer and use it in GitHub Desktop.
Save Nalini1998/97ad6cee9a25181cf380c5439de54b1f to your computer and use it in GitHub Desktop.
The map() method
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