为什么将映射运算符结果分配给数组?

why map operator result is assigned to an array?

我担心的是这段代码

    export class RatingInputComponent {
      stars: boolean[] = Array(5).fill(false);
      get value(): number {
        return this.stars.reduce((total, starred) => {
          return total + (starred ? 1 : 0);
    }, 0);
  }
  rate(rating: number) {
    this.stars = this.stars.map((_, i) => rating > i);
  }

map 运算符应该 return 一个可观察对象,但结果被分配给一个数组,结果不应该被分配给一个可观察对象 谢谢

您的问题是混淆了 map():数组方法和 map(),即 RXJS 方法。显然你的一堆代码正在使用数组方法。此处使用的 reduce 也是如此。