JSFiddle - React, Tailwind, and code Playground

by sifriday

JavaScript

// Your list
list = ["a", "b", "c", "d"]

// Store the deferreds here, so we can resolve them via a timeout
dfds = []

for (var i = 0; i < list.length; i+=1) {
    var d = $.Deferred()
    var p = d.promise()
    p.index = i
    p.done(function(result) {
         console.log(list[this.index]) 
    })
    dfds.push(d)
}
  
// Resolve the deferreds via timeout in lieu of doing real work
var i = 0, dfd
while (dfd = dfds[i]) {
    dfd.resolve()
    i++
}