const { Observable } = require('rxjs'); const myObservable = new Observable((observer) => { observer.next('Hello'); observer.next('World'); observer.complete(); });
const { from } = require('rxjs'); const { map } = require('rxjs/operators'); const myArray = [1, 2, 3, 4, 5]; const myObservable = from(myArray).pipe( map(num => num * 2) ); myObservable.subscribe(value => console.log(value));This example code uses the `from` operator to create an `Observable` from an array, and then uses the `map` operator to transform the emitted values by doubling them. The final result is that the `Observable` emits the values `[2, 4, 6, 8, 10]`. The `subscribe` method is used to subscribe to the `Observable` and log the emitted values to the console. Both these examples use the RxJS library.