Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/mod.ts>forEach

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function forEach
import { forEach } from "https://deno.land/x/iter@v3.2.3/mod.ts";

Performs the specified action for each item in an iterable, consuming the iterable in the process.

Examples

Example 1

import * as iter from "https://deno.land/x/iter/mod.ts";

const naturals = iter.create.increments(1);
const first6 = iter.take(naturals, 6);
iter.forEach(first6, x => console.log(x));

// -> 1
// -> 2
// -> 3
// -> 4
// -> 5
// -> 6

Parameters

it: Iterable<T>
  • The iterable being looped over.
  • A function that accepts up to three arguments. forEach calls f one time for each item in the iterable.