Array reduceRight() and asynchronous function callback - Javascript Array

Javascript examples for Array:reduceRight

Description

Array reduceRight() and asynchronous function callback

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var func = function(arg, next) {
  setTimeout(function(){/*from  w w  w .  ja  v a 2 s.c  o  m*/
    console.log(arg);
    next();
  }, 1000);
};
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var fn = arr.reduceRight(function (a, b) {
  return func.bind(null, b, a);
}, function (){
  console.log('finish');
});
fn();

      </script>  
   </body>
</html>

Related Tutorials