0

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.

0

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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")
    ]
);

3 Comments

I am getting an error on the first example. Supplied parameters do not match any signature of call target.
I tried on typescriptlang.org/play and it seems to work fine
here is my day.dto.ts class declaration {namespace Bidding { export class DayDto { dayOfMonth: string; weekEnd: boolean; payPeriodEnd: string; } }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.