Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to set a timeout on an array element

   
function ArrayPlusDelay(array, delegate, delay) {
  var i = 0
  
  function loop() {
  	  // each loop, call passed in function
      delegate(array[i]);
      
      // increment, and if we're still here, call again
      if (i++ < array.length - 1)
          setTimeout(loop, delay); //recursive
  }

  // seed first call
  setTimeout(loop, delay);
}

// call like this
ArrayPlusDelay(['d','e','f'], function(obj) {console.log(obj)},1000)
Comment

how to set a timeout on an array element

function ArrayPlusDelay(array, delegate, delay) {
  var i = 0
  
   // seed first call and store interval (to clear later)
  var interval = setInterval(function() {
    	// each loop, call passed in function
      delegate(array[i]);
      
        // increment, and if we're past array, clear interval
      if (i++ >= array.length - 1)
          clearInterval(interval);
  }, delay)
  
}

ArrayPlusDelay(['x','y','z'], function(obj) {console.log(obj)},1000)
Comment

how to set a timeout on an array element

var ary = ['kevin', 'mike', 'sally'];

for(let i = 1; i <= ary.length; i++){
    setTimeout(function(){
        console.log(ary[i - 1]);
      }, 5000 * i); 
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: fontsize javascript 
Javascript :: split first character of string in javascript 
Javascript :: javascript child element selector 
Javascript :: JS how to determine if page was cached 
Javascript :: new map js 
Javascript :: odd even javascript 
Javascript :: rgb to hex conversion 
Javascript :: change inside div with jquery 
Javascript :: axios post nuxt 
Javascript :: async wait for axios reactjs 
Javascript :: DatabaseError [SequelizeDatabaseError]: relation does not exist 
Javascript :: jquery check is select 
Javascript :: javascript get type of var 
Javascript :: remove everything from mongodb databaase mongoose 
Javascript :: onpress setstate react native 
Javascript :: docker remove json log 
Javascript :: event loop in javascript 
Javascript :: update angular project 
Javascript :: parse date without timezone javascript 
Javascript :: disable link react 
Javascript :: unix to time in javascript 
Javascript :: isChecked radio button jQuery 
Javascript :: react native vector icons link 
Javascript :: prependchild javascript 
Javascript :: how to make a post request from axios 
Javascript :: jquery once 
Javascript :: jason in javascript 
Javascript :: fetch json data into array 
Javascript :: js add class to html 
Javascript :: javascript rect 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =