Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Creating a Stream from an Array of Items Using the RxJS From Operator

    Laurie BarthLaurie Barth
    rxjsRxJS

    Use the RxJS from operator to create a stream with an array of data. Use the interval and zip operators to time delay each element in the stream.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: Begin by importing the from operator from RxJS. Next, define an observable using the from operator, passing in an array of numbers. In order to use the observable, we'll subscribe to it and pass in an observer that logs out the value.

    As we can see, all of the numbers appear at once. We'll use the interval operator to define an observable that has a time series.

    Finally, we'll use the zip operator to define another observable that takes in our from observable and our timed interval observable. We'll subscribe to our zipped observable. As we can see, we're logging an array.

    We'll use destructuring assignment to access the first element in that array, the returned number from our from observable.

    There we have it, each element in our array appearing in a time-delayed stream.