In python, if I want to create an array like [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] I only need to do [1] * 10
>>> [1] * 10
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Can I achieve the same in typescript?
you can try out
Array.from({ length: 10}, () => 1) - with this you can provide function that can initialize your array with the function output , currently function returns 1 so it initialize array with 1.
or
new Array(10).fill(1); (Already as given in comment)
const array = new Array(10).fill(1);