[removed] recursive function returns undefined for existing value

前端 未结 1 1046
囚心锁ツ
囚心锁ツ 2020-12-21 17:21

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 stop

相关标签:
1条回答
  • 2020-12-21 18:13

    You have to return the value from the recursive call,

      // recall with updated index
      return 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

    0 讨论(0)
提交回复
热议问题