Unexpected NaN results when using Array.flatMap with non-numeric values in TypeScript
I've been researching this but I am currently working on a TypeScript project where I'm using `Array.flatMap` to transform and flatten an array of objects. The array contains a mix of numeric and non-numeric values, and I expect the output to only include numerical values, but I keep getting `NaN` in the result. Hereβs a snippet of what I tried: ```typescript interface Item { value: number | string; } const items: Item[] = [ { value: 1 }, { value: 'two' }, { value: 3 }, { value: null }, { value: 5 }, ]; const result = items.flatMap(item => { const num = Number(item.value); return isNaN(num) ? [] : [num]; }); console.log(result); ``` When I run this code, I expected `result` to be `[1, 3, 5]`, but instead, I am seeing `[1, 3, 5, NaN]`. Iβve also tried using `filter` alongside `flatMap`, but I still end up with `NaN` in the output. I am using TypeScript version 4.5.2 and targeting ES2020. Is there something Iβm missing, or is there a better way to achieve this without ending up with `NaN` in the output? Any insights or alternative approaches would be greatly appreciated! The stack includes Typescript and several other technologies. Any pointers in the right direction?