0

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.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Robb1
  • 4,587
  • 6
  • 31
  • 60

2 Answers2

1

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)
)
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0

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);
Akshay Bande
  • 2,491
  • 2
  • 12
  • 29