Skip to content Skip to sidebar Skip to footer

Synchronous Iterator Skips First Item In Array

it's a part of a utility library for angular, but i'll copy just the function its self here to make it easy to reproduce the problem. the problem is that for some reason there is 1

Solution 1:

In the first iteration you are passing 0 as result.

if(result) {
    results.push(result);
}

will be false (Boolean(0) is false) so 0 is never added to the results array.


For result you can just compare it against undefined:

if (result !== undefined)

For error, you can use loose comparison against null, which handles nullandundefined:

if(error!=null)

Solution 2:

Solution 3:

0 is falsy in javascript. Thus when doing:

if(result)
    results.push(result);

if result is 0 then it won't get pushed. To check if result is defined use this:

if(result !== undefined)
    results.push(result);

Post a Comment for "Synchronous Iterator Skips First Item In Array"