How to use JavaScript forEach()

arrA.forEach( callbackFucntionB[, thisArgC ] )

  • callbackFucntionB
    • Parameters
      • value // current process value
      • index // current process index
      • array // arrA
  • thisArgC
    • ‘this’ in callbackFucntionB

 

Example

[2, 5, 9].forEach(function( v, i, arr ) {
console.log( v, i, arr );
});

 

Links

//

Javascript check css animation complete callback

CSS aniamation complete check callback event

var transitions = {
‘transition’:’transitionend’,
‘OTransition’:’oTransitionEnd’,
‘MozTransition’:’transitionend’,
‘WebkitTransition’:’webkitTransitionEnd’
}

https://davidwalsh.name/css-animation-callback

JavasScript forEach using Array initialize

# forEach loop using array

// All borwser support
ㅇ Array.apply(null, Array(10))
Array.apply(null, Array(6)).forEach((_,i) => { console.log(i) });

ㅇ using string
new Array(10).join().split(“,”).forEach((_,i) => { console.log(i) });
new Array(10).toString().split(“,”).forEach((_,i) => { console.log(i) });

// Not working on IE
ㅇ fill method
Array(length).fill(default value);
Array(4).fill(1);
// https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/fill

# initialize javascript array with initial value
var a = Array.apply(null, Array(24)).map(function() { return 0 });
var a = function _re(n){if(n > 0) return _re(n-1).concat(n); return [0];}(10);