Skip to content

Array sum

JavaScript for-of

Same task in: CTypeScript

Flowchart (ISO 5807)

StartInput arrs = 0x ∈ arrs = s + xReturn sEndFigure 1 — sum

Source code

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

The editor opens with this code — change it and the chart redraws.

Language
JavaScript
Constructs
for-of
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples