DEV Community

Discussion on: Some awesome js tricks you should know about

Collapse
tqbit profile image
tq-bit • Edited on

don't forget the invaluable array.map() method. Basically an abbreviation of array.forEach(), but executes a callback on each array element and returns an array with the mutated values.

const nums = [1, 15, 30];
const numsPlusTen = nums.map((num) => num + 10);
console.log(numsPlusTen); // Returns [11, 25, 40]
Enter fullscreen mode Exit fullscreen mode
Collapse
is_ellie profile image
Ellie Author

Haha right, .map() could basically do all forEach() could do, thanks for commenting btw!