I have the following array in Typescript:
this.days_in_month = [
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
];
I want to loop through it, and for every value create a new, empty, array of length of that value and add that array to another array of arrays.
Eg: the first value is 31 so I would create an empty array 31 things long and add the 31-array to an array of arrays. The next value is 28 so I would then create an array 28 things long and then add the 28-array to the array of arrays so that it now contains the 31-array and the 28-array.
In Python I would use range, but I'm not sure how to do this in Typescript.
So far I have the following ts:
this.days_in_month.forEach(function(value, index, array) {
console.log(value, index, array);
no_of_days: number = this.days_in_month(value);
let days = new Array<number>(no_of_days);
})
See Question&Answers more detail:
os