I'm a total newbie in JavaScript
. I'm trying to learn it using programming experience in Python
...
Let's say there is an array of integers [2,3,4,5]
. I want to get sum of all items in it with for
loop. In Python
this gonna looks like
list_sum = 0
for i in [2,3,4,5]:
list_sum += i
Result is 14
But if I try same in JavaScript
:
var listSum = 0;
for (i in [2,3,4,5])
{
listSum += i;
}
This will return 00123
. Seems that item indexes concatenated in a string with initial listSum
value. How to make code works as intended and to get sum of all array items as integer?