asynchronous for loop with if conitions protractor
<pre><code>    var createTime=10:00;
    var createdPatient="vijay";
    /* In for loop after comparing the time with createdTime 'i' value should be the compare index but 'i' value becoming last index each time*/ 
    element(by.xpath("//div[@id='patients']")).all(by.xpath("div[@class='ng-scope']")).then(
function(divtags){
for(i=0;i&lt;divtags.length;i++){
divtags[i].element(by.xpath("div[1]/div[2]")).getText().then(function(time){
if(time==createdTime){
 /*Here i am getting 'i' value every time last divtag length */        divtags[i].element(by.xpath("div[@class='patient']")).getText().then(function(patientName){
if(patientName==createdPatient){
divtags[i].click();
}})}});}});
</code></pre>

<p>Please tell me how to get the correct index 'i' value after comparing the time with created time in protractor for loop code.</p>