what is difference between 'of' and 'from' in Rxjs

questionsCategory: Questionswhat is difference between 'of' and 'from' in Rxjs
Sandhya asked 2 years ago

hi i want to lean Rxjs. i have a doubt when to use ‘of’ and when to use ‘from’. please give a sample example

1 Answers
Satya answered 2 years ago

Hi sandhya, see below example to find difference between ‘of’ and from in Rxjs
Use of ‘of’ in Rxjs
const cities = [“delhi”,”mumbai”, “pune”];
Rx.Observable.of(cities).subscribe(cities=>{console.log(cities)})
Result:
[“delhi”, “mumbai”, “pune”]
Use of ‘from’ in Rxjs
const cities = [“delhi”,”mumbai”, “pune”];
Rx.Observable.from(cities).subscribe(cities=>{console.log(cities)})
Result:

  • “delhi”
  • “mumbai”
  • “pune”

I hope your doubt would be clear.