Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

formatting and grammatical improvement(s)
Source Link

I'm surprised no one yet havehas suggested using the forEachforEach function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].forEach(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

// edited to use forEachforEach instead of map.

I'm surprised no one yet have suggested using the forEach function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].forEach(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

// edited to use forEach instead of map.

I'm surprised no one yet has suggested using the forEach function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].forEach(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

// edited to use forEach instead of map.

use forEach instead of map.
Source Link
Christian Landgren
  • 13.9k
  • 6
  • 37
  • 31

I'm surprised no one yet have suggested using the mapforEach function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].mapforEach(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

// edited to use forEach instead of map.

I'm surprised no one yet have suggested using the map function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].map(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

I'm surprised no one yet have suggested using the forEach function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].forEach(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3

// edited to use forEach instead of map.

Source Link
Christian Landgren
  • 13.9k
  • 6
  • 37
  • 31

I'm surprised no one yet have suggested using the map function to better avoid (re)using local variables. In fact, I'm not using for(var i ...) at all anymore for this reason.

[0,2,3].map(function(i){ console.log('My value:', i); });
// My value: 0
// My value: 2
// My value: 3
lang-js

AltStyle によって変換されたページ (->オリジナル) /