JSFiddle - React, Tailwind, and code Playground

HTML

<div id="name0">Zero</div>
<div id="name1">One</div>
<div id="name2">Two</div>

JavaScript

// This function returns a function that has a different scope outside of the for-loop, so the value of `i` is reserved.
var getCallback = function(index) {
    return function(){
        // You can see how this is captured correctly now in Javascript console
        console.log(index);
        $('#name' + index).show('slide',{direction: "up"}, 1000)
    };
};

for (var i = 0; i < 3; ++i) {
    $('#name'+i).show("slide", {direction: "right"}, 1000, getCallback(i));
}