Is there a simple way in TypeScript to generate an array of the first 10 integer numbers?
Such as I would do with Matlab with x = 1:10
.
Is there a simple way in TypeScript to generate an array of the first 10 integer numbers?
Such as I would do with Matlab with x = 1:10
.
You can use Array.from
with a map function where you can use index inside map function o generate the number.
console.log(
Array.from({ length: 10 }, (_, i) => i + 1)
)
You can do it using Array.prototype.fill
and Array.prototype.map
let arr = Array(10).fill(0);
arr = arr.map((val, index) => index + 1);
console.log(arr);