You are using the loop index i inside a function that is invoke asynchronously.
Try changing this:
console.log('response2-->',response[i]);
to this:
console.log('response2-->',response[0]);
---
R. Mark Volkmann
Object Computing, Inc.
> On Oct 27, 2017, at 12:54 PM, [email protected] wrote:
>
> Thank you for the response. Below is my code:
> for(var i=0;i<response.length;i++){
> var messageTimeStamp = response[i].messageTimeStamp;
> console.log('messageTimeStamp-->'+messageTimeStamp);
> var body = {deviceId:req.body.deviceId};
> console.log('response1-->',response[i]);
> Custody.find(body, function(error, custodyResponse) {
> if(custodyResponse.length == 1){
> console.log('custodyResponse.length-->'+custodyResponse.length);
> console.log('response2-->',response[i]);
>
> }
>
> });
>
> here I am getting value for response1 but not for response2
>
> Regards
>
>> On Tuesday, October 24, 2017 at 4:57:58 PM UTC-4, [email protected] wrote:
>> Hi
>> I am new to node js. I am facing an issue.
>> I have 3 ids. I am iterating in for loop. For each value I am calling web
>> service. The web service is find by id by passing each id. What I noticed is
>> that it always takes the last id.
>> for eg: id are 10, 20, 30
>> When I call any service by passing in for loop it always takes 30.
>> Any help is appreciated.
>>
>> Regards
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/572a0df8-4ecf-43e0-9ee4-fe3757bc8cd1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/D7E70427-F29B-42D7-AA04-E2731306B5D8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.