+ 2
Why this code gives undefined 🤔
Please anyone help me in this code. Why this give undefined?? https://code.sololearn.com/WwIhNM9Y82sR/?ref=app
5 Respostas
+ 5
Akash Agrawal the "return true" code is returning the function provided as parameter for arr.forEach not the show function. If you want to return true try this:
for (let i of arr)
if (i==5) return true;
See more about array. forEach here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
+ 5
Because your function is not returning anything.
+ 3
Thanks VEDANG
+ 2
VEDANG but why my function is not return true
+ 2
A forEach loop cannot be broken before completion. You can use a traditional for loop as VEDANG suggested. Or use recursion
https://code.sololearn.com/WymH0U5NRiBf