0

Im a beginner to coding JS. When im trying to create an array function for diplaying object reference. I write it on the VS code. See the image for the details.

The problem is that i want to remove the 'undefined' status that is printed on the cmder. Im using Node and cmder to run the code.

Hope this clear for you to understand my problem. Thanks

4
  • 1
    You're printing values inside your for each, and then printing the return of foodList (which is undefined since forEach will return undefined). Call your foodList method without the console.log Commented Jan 13, 2020 at 11:41
  • 3
    Pictures of code or of exceptions are not very helpful. Put a minimal reproducible example and (if applicable) text of the exception in the question itself. The editor has buttons and instructions to help you format it so it is readable. Provide a live demo if you're asking about HTML/JavaScript/CSS. Commented Jan 13, 2020 at 11:42
  • A tip from my side, since you want to perform an action on an array, I'd suggest you to take a moment and read the following article: medium.com/poka-techblog/… Regarding your original question: const foodList = items.forEach(.......) will fix it Commented Jan 13, 2020 at 11:48
  • Okay thanks! Sorry, im a beginner and just tried the first time i used stackoverflow. Really helps and sorry for the inconvenience! Commented Jan 13, 2020 at 11:59

3 Answers 3

2
  • You are logging the return value of foodList.
  • foodList returns the return value of forEach.
  • forEach always returns undefined

If you don't want to log that, then remove the console.log() from around the return value of foodList.

Sign up to request clarification or add additional context in comments.

Comments

1

You are doing

console.log(foodList(animal))

this console.log is returning undefined

do this

foodList(animal)

Comments

0

Yes, it's my fault, i didnt know that console.log return undefined when using forEach(). Sorry everyone, my bad. Thanks for the helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.