Sign in
Log inSign up

What does the last parameter (this) do in the forEach function?

Dandy Cheng's photo
Dandy Cheng
·Sep 15, 2017

e.g.

[1,2,3].forEach(function(x){
    console.log(k[x])
},this)

I also realized that I get an undefined after looping the array. Why is that?

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct