Array.prototype.includes vs. Array.prototype.indexOf

tl;dr: NaN is treated differently: [NaN].indexOf(NaN) > -1 is false [NaN].includes(NaN) is true From the proposal: Motivation When using ECMAScript arrays, it is commonly desired to determine if the array includes an element. The prevailing pattern for this is if (arr.indexOf(el) !== -1) { … } with various other possibilities, e.g. arr.indexOf(el) >= 0, or … Read more

How can I `await` on an Rx Observable?

You have to pass a promise to await. Convert the observable’s next event to a promise and await that. if (condition) { await observable.first().toPromise(); } Edit note: This answer originally used .take(1) but was changed to use .first() which avoids the issue of the Promise never resolving if the stream ends before a value comes … Read more