Skip to content

Step argument to return multiple array entries in one iteration #1

@richrdkng

Description

@richrdkng

For arrays, provide a way to get more, than one argument in on iteration.

let array = [1, 2, 3, 4];

// values only
foreach(
    array,
    2, // step by two
    (a, b) => {
        // 1, 2, then next will be 3, 4
        console.log(a, b);
    }
);

// values with indices
foreach(
    array,
    2, // step by two
    (ai, av, bi, bv) => {
        // '0 : 1, 1 : 2', then next will be '2 : 3, 3 : 4'
        console.log(`${ai} : ${av}, ${bi} : ${bv}`);
    }
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions