Created
April 19, 2017 10:54
-
-
Save SergeyLipko/319da288857a2412db61c3067e5736b2 to your computer and use it in GitHub Desktop.
How Array.prototype.map() and Array.prototype.forEach() works
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
const myArr = [1, 2, 3, 4, 5, 6]; | |
// map создает новый массив на основании вызова callback для каждого элемента (трансформация) | |
const newMap = myArr.map(i => { | |
return i * 2; | |
}); | |
// forEach выполняет callback для каждого элемента массива (перебор) | |
const newForEach = myArr.forEach(i => { | |
return i * 2; | |
}); | |
console.log(newMap); // 2, 4, 6, 8, 10, 12 | |
console.log(newForEach); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment