⚠️ This lesson is retired and might contain outdated information.

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

Laurie Barth
InstructorLaurie Barth
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 2 years ago

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.

Instructor: [00:01] 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.

[00:27] 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.

[00:40] 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.

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

[01:14] There we have it, each element in our array appearing in a time-delayed stream.

egghead
egghead
~ 4 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today