🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 14 : 04 : 37
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

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

Unlock All Content for 40% Off
1×
Become a member
to unlock all features
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.