You have to put this line
console.log("count repetidos 2",countRepetidos); // value undefined
before the return function
return resolve(countRepetidos);
var countRepetidos;if(obj.data.list!={} && obj.data.list.length>0){
var aux = obj.data["list"];
countRepetidos=0;
for(var i=0;i<aux.length;i++){
Database.Probing.getMacAdress(aux[i]).then(function(data){
if(data.count>0){
countRepetidos++;
console.log("count repetidos 1",countRepetidos); // value 116
}
});
}
console.log("count repetidos 2",countRepetidos);
return resolve(countRepetidos);}
On 21 July 2017 at 08:54, Catia Matos <[email protected]> wrote:
>
> 0down votefavorite
> <https://stackoverflow.com/questions/45236919/outside-for-loop-var-value-is-undefined#>
>
> I'm facing a problem with a value where inside my for cycle it has values
> like "179" and outside i get always undefined. Why?
>
> var countRepetidos;if(obj.data.list!={} && obj.data.list.length>0){
> var aux = obj.data["list"];
> countRepetidos=0;
> for(var i=0;i<aux.length;i++){
> Database.Probing.getMacAdress(aux[i]).then(function(data){
> if(data.count>0){
> countRepetidos++;
> console.log("count repetidos 1",countRepetidos); // value 116
> }
> });
> }
> return resolve(countRepetidos);}
>
> console.log("count repetidos 2",countRepetidos); // value undefined
>
> log :
>
> 3|wscontro | count repetidos 1 1163|wscontro | count repetidos 2 undefined
>
> I try instead of use resolve, use callback but nothing... I saw other
> answers in javascript but for node.js I cant resolve this problem... I saw
> the link refering thus question as a duplicate but cant figure out a
> solution to this case.
>
> --
> 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/743beb4c-731e-4d2c-8055-bdf1804c4595%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/743beb4c-731e-4d2c-8055-bdf1804c4595%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
[]'s
--
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/CAET7tnaA912n2_UgKGmS9dxAtsbfOgfxzgaDPMegazHiYeXkCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.