Creating a Typescript Javascript Array with 10 Undefined Items

Ole Ersoy
Jul 8, 2023

--

Scenario

We want a typescript array with 10 undefined items that we can map over.

Approach

const a: undefined[] = Array.from(Array(10));
console.log(a);
const b: 1[] = a.map((i) => 1);
console.log(b);

Demo

--

--