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.

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

  • rangeGenerator

    JavaScript, Function

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

  • repeatGenerator

    JavaScript, Function

    Creates a generator, repeating the given value indefinitely.

  • cycleGenerator

    JavaScript, Function

    Creates a generator, looping over the given array indefinitely.

  • generatorToArray

    JavaScript, Function

    Converts the output of a generator function to an array.

  • isGeneratorFunction

    JavaScript, Type

    Checks if the given argument is a generator function.

  • chunkify

    JavaScript, Function

    Chunks an iterable into smaller arrays of a specified size.

  • dateRangeGenerator

    JavaScript, Date

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

  • indexOfSubstrings

    JavaScript, String

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

  • walkThrough

    JavaScript, Object

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

  • generateWhile

    JavaScript, Function

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

  • generateUntil

    JavaScript, Function

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

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

  • Enums are part of TypeScript, but what about defininf enums in plain old JavaScript? Here are a few way you can do that.

  • Learn how you can leverage the Proxy object to use a JavaScript object the same way as you would use a regular array.