Answer the question
In order to leave comments, you need to log in
Stack elements in JavaScript array?
Here is the condition.
var list = [1, 2, 3, 4, 5, 6];
function sum() {
var sum = 0;
for (i=0; i<arguments.length; i++) {
sum += arguments[i];
}
}
Подсчитать с помощью функции
sum
сумму элементов
list
Answer the question
In order to leave comments, you need to log in
It is necessary to calculate in a cunning way, but at the expense of editing, most likely this is a mistake of the author of this site
var list = [1, 2, 3, 4, 5, 6];
function sum() {
var sum = 0;
for (i=0; i<arguments.length; i++) {
sum += arguments[i];
}
return sum
}
sum.apply(null, list) // output => 21
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question