how to use the sequenceequal function from the rxjs library in javascript

To use the sequenceEqual function from the RxJS library in JavaScript you need to follow these steps:

  1. Import the sequenceEqual function from the rxjs/operators module:
index.tsx
import { sequenceEqual } from 'rxjs/operators';
48 chars
2 lines
  1. Create two observable streams that emit the values you want to compare:
index.tsx
import { from } from 'rxjs';

const stream1$ = from([1, 2, 3]);
const stream2$ = from([1, 2, 3]);
98 chars
5 lines
  1. Use the sequenceEqual function with the two streams as arguments to compare their emitted values:
index.tsx
const isEqual$ = sequenceEqual(
  stream1$,
  stream2$
);

isEqual$.subscribe(result => {
  console.log(result);
  // Output: true
});
135 chars
10 lines

The isEqual$ observable will emit a boolean value true if the values emitted in both streams are equal, and false otherwise.

gistlibby LogSnag