-1
Returns undefined
because you are asking for the method sumario()
return of array method forEach
, and this method by default executes a callback function for each element of the array and always returns the value of undefined
.
You can see it through this Developer Mozilla link, where he says the following:
''
forEach()
executes the callback function once for each element of the array - unlikemap()
orreduce()
, it always returns the valueundefined
and is not chained. The typical use case is to change the array at the end of the loop. ''.
If you don’t want to see the undefined
, rewrite: console.log(conta.sumario())
thus conta.sumario();
Don’t post code as image, it’s bad to read and even worse to try to simulate your problem
– Jefferson Quesado
The method
.forEach
always returnsundefined
. What was the result you hoped to achieve? You may want to use another method but only knowing what you expect we can help you more.– Sergio