← All examples

Array sum

JavaScript Loops

for-of

Flowchart (ISO 5807)

StartInput arrs = 0x in arrs += xReturn sEndFigure 1 — sum

Source code

function sum(arr) {
    let s = 0;
    for (const x of arr) {
        s += x;
    }
    return s;
}