JavaScript Generator Functions

JavaScript generator functions introduce a way to define an iterative algorithm by writing a function with non-continuous execution. This practically means they allow you to create a new generator every time you call a generator function, which can then be iterated over just like any other iterable.

  • Using JavaScript generator functions for ranges

    Learn how to use JavaScript ES6 generators and iterators to iterate over ranges of numbers.

    JavaScript, Function · Jun 12, 2021

  • Range generator

    Creates a generator, that generates all values in the given range using the given step.

    JavaScript, Function · Oct 11, 2020

  • Repeat generator

    Creates a generator, repeating the given value indefinitely.

    JavaScript, Function · Oct 11, 2020

  • Cycle generator

    Creates a generator, looping over the given array indefinitely.

    JavaScript, Function · Oct 11, 2020

  • Generator to array

    Converts the output of a generator function to an array.

    JavaScript, Function · Dec 31, 2020

  • Value is generator function

    Checks if the given argument is a generator function.

    JavaScript, Type · Oct 20, 2020

  • Chunk iterable

    Chunks an iterable into smaller arrays of a specified size.

    JavaScript, Function · Mar 16, 2021

  • Date range generator

    Creates a generator, that generates all dates in the given range using the given step.

    JavaScript, Date · Jun 21, 2021

  • Index of substrings

    Finds all the indexes of a substring in a given string.

    JavaScript, String · Dec 31, 2020

  • Walk through object

    Creates a generator, that walks through all the keys of a given object.

    JavaScript, Object · Nov 15, 2021

  • Generate while condition is met

    Creates a generator, that keeps producing new values as long as the given condition is met.

    JavaScript, Function · Jan 21, 2022

  • Generate until condition is met

    Creates a generator, that keeps producing new values until the given condition is met.

    JavaScript, Function · Jan 21, 2022

  • Left substring generator

    Generates all left substrings of a given string.

    JavaScript, String · Jul 24, 2022

  • Right substring generator

    Generates all right substrings of a given string.

    JavaScript, String · Jul 25, 2022

  • Tip: Make any JavaScript value iterable

    Did you know you can define an iterator for any JavaScript value? This quick tip will show you how.

    JavaScript, Array · Jun 12, 2021