• Read the arguments from the provided array, iterator / or generator function When processing an Iterable and a negative start or end is provided the entire iterator will be processed into an array before applying the start / end restrictions and when undefined or >= 0 any iterator will not be fully processed.

    Type Parameters

    • T = any

    Parameters

    • theArgs: ArrayLike<T> | Iterable<T>

      The arguments to process, may be ArrayLike or an Iterable

    • Optional start: number

      Zero-based index at which to start extraction, converted to an integer.

      • Negative index counts back from the end of the array or iteration
      • if start < 0, start + (array.length || iterator.count) is used.
      • If start < -array.length or start is omitted, 0 is used.
      • If start >= array.length, nothing is extracted.
    • Optional end: number

      Zero-based index at which to end extraction, converted to an integer. readArgs() extracts up to but not including end.

      • Negative index counts back from the end of the array — if end < 0, end + array.length is used.
      • If end < -array.length, 0 is used.
      • If end >= array.length or end is omitted, array.length is used, causing all elements until the end to be extracted.
      • If end is positioned before or at start after normalization, nothing is extracted.

    Returns T[]

    A new array with the extracted elements

    Example

    function myFunc<T>(firstArg: T, ...otherArgs) {
    // Read all of the arguments
    let allArgs = readArgs(arguments);

    // Get all of the arguments after the first
    let optArgs = readArgs(arguments, 1);
    }

    myFunc("Hello");
    myFunc("Hello", "Darkness", "my", "old", "friend", ".");

    function* myGenerator() {
    yield "Hello";
    yield "Darkness";
    yield "my";
    yield "old";
    yield "friend";
    }

    function* myGenerator2() {
    yield "I've";
    yield "come";
    yield "to";
    yield "talk";
    yield "with";
    yield "you";
    yield "again";
    }

    readArgs(myGenerator());
    // [ "Hello", "Darkness", "my", "old", "friend"]);

    readArgs(myGenerator(), 1);
    // [ "Darkness", "my", "old", "friend"]);

    readArgs(myGenerator2());
    // [ "I've", "come", "to", "talk", "with", "you", "again" ]);

    readArgs(myGenerator2(), 0, -2);
    // [ "I've", "come", "to", "talk", "with" ]);

    readArgs(myGenerator2(), -3, -2);
    // [ "with" ]);