使用轉換函式和元素索引

const source = Rx.Observable.range(1, 3)
  .map((x, idx, obs) => `Element ${x} was at position ${idx}`);

const subscription = source.subscribe(
  x => console.log(`Next: ${x}`),
  err => console.log(`Error: ${err}`),
  () => console.log(`Completed`)
);

// => Next: Element 1 was at position 0
// => Next: Element 2 was at position 1
// => Next: Element 3 was at position 2
// => Completed