Reputation: 41
I am trying to push one array object into another in typescript. Here is what i have:
days: DayDto[];
while (startsOn.toDate() < endsOn.toDate())
{
var newDate = startsOn.add(1, 'days');
startsOn = moment(newDate);
let d = this.getDayOfWeek(newDate.isoWeekday()) + newDate.date().toString();
let w = this.getDayOfWeek(newDate.isoWeekday()) == "Sa" ? true : this.getDayOfWeek(newDate.isoWeekday()) == "Su" ? true : false;
this.temp = new DayDto;
this.temp.dayOfMonth = d;
this.temp.weekEnd = w;
this.temp.payPeriodEnd = "S31";
//this.days.push(
// [
// new DayDto( d, w, "S31")
// ]
//);
}
So, I have a loop that while startsOn is less than endsOn, it loops through and gets the day of the week (Su) and the day of the month (21) and puts those into d and w. then those are put into the this.days array at the end of each loop. But i cannot get the logic correct for adding them to the array.
Upvotes: 0
Views: 16950
Reputation: 2701
typescript supports es6, if you want to combine two array, you can do something like this
var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
arr1.push(...arr2);
for detail information, https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator , your question is unclear.
Upvotes: 6
Reputation: 24979
I don't know if I have fully understood your question.
If days
is DayDto[]
:
class DayDto {
constructor(
public dayOfMonth: number,
public weekEnd: number,
public payPeriodEnd: string
) {}
}
var days: DayDto[] = [];
days.push(
new DayDto(5, 5, "S31")
);
If days
is DayDto[][]
:
class DayDto {
constructor(
public dayOfMonth: number,
public weekEnd: number,
public payPeriodEnd: string
) {}
}
var days: DayDto[][] = [];
days.push(
[
new DayDto(5, 5, "S31"),
new DayDto(5, 5, "S31")
]
);
Upvotes: 0