Replace your loops by Array methods - map()
Fernando Daciuk
152

Code:
[1, 2, 3].forEach(function(item) {
 console.log(this);
}, [4, 5, 6]);

Expected output (by author):
→ 4
→ 5
→ 6

Real output:
→ [4, 5, 6]
→ [4, 5, 6]
→ [4, 5, 6]

To get expected output code should be:
[1, 2, 3].forEach(function(item, index) {
 console.log(this[index]);
}, [4, 5, 6]);

Show your support

Clapping shows how much you appreciated Сергей Дмитриев’s story.