Skip to content Skip to sidebar Skip to footer

Javascript: Recursive Function Returns Undefined For Existing Value

I am trying to loop an array using a recursive function. The loop should stop and return the value of the key, if it matches a given regex pattern. The loop stops correctly whe

Solution 1:

You have to return the value from the recursive call,

// recall with updated indexreturn loop(arr,i); 
}

The final call for the function loop will return a value, but the other calls for the same function returns undefined. So finally you end up in getting undefined

Post a Comment for "Javascript: Recursive Function Returns Undefined For Existing Value"