Typed Array Methods
map, filter, reduce, find, some, every and flatMap keep their types, and generics let TypeScript infer results.
Example
const n = [1, 2, 3, 4, 5];
console.log(n.map((x) => x * 2));
console.log(n.filter((x) => x % 2 === 0));
console.log(n.reduce((a, b) => a + b, 0));
console.log(n.find((x) => x > 3), n.some((x) => x > 4), n.every((x) => x > 0));Result
[ 2, 4, 6, 8, 10 ] [ 2, 4 ] 15 4 true true
Exercise
Combine to one value.
n.((a, b) => a + b, 0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.