-7

I am stuck with some of concepts in forEach. Referred some of sites to clear my thought about why return inside forEach always returns undefined where map, find statements returns the values but not getting correct idea. anyone please redirect me to correct websites if there or please clear my doubt.

Thanks!

user10269224
  • 73
  • 10
  • 4
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Zakaria Acharki Sep 14 '18 at 11:33
  • 2
    Not clear what your asking, Array.forEach() returns undefined by design (what else would it return?) – Alex K. Sep 14 '18 at 11:34
  • my doubt is not code related i am working. But always i want to return a specific thing from an array conditionally, return statement results undefined – user10269224 Sep 14 '18 at 11:35
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Return_value – Calvin Nunes Sep 14 '18 at 11:37
  • Possible duplicate of [What does \`return\` keyword mean inside \`forEach\` function?](https://stackoverflow.com/questions/34653612/what-does-return-keyword-mean-inside-foreach-function) – VLAZ Sep 14 '18 at 11:39

1 Answers1

0

so basically when you use forEach you say that you want to a particular thing for every element, note that to accomplish that task you dont need to return anything and even if you do, just think what use will it be ?

but when you map you want every element to be converted to something, now this something has to be the return value of the function inside map

ashish singh
  • 6,526
  • 2
  • 15
  • 35