Someguy
Someguy

Reputation: 414

Adding an Array to an Array in Angular

So I have a db document that holds some string values in an array, I want to push just the array from every entry into an array in the application for usage later, But I can see the array fine on the fetch, and when I iterate it but my "Global array" is staying empty can someone explain why?

specialDates : Specialdates[] = [];
specialRange: any[] = [];
this.specialDates.forEach(ag => {      
//ag,range -> I can see fine
   this.specialRange.push(ag.range);
//this.specialrange -> Stays empty 
});

Array looks something like the following:

1205,1206,1207,1208

What is wrong with this approach?

Reason for doing this is because the documents have 2 fields minimum: EG -> ID/Array

And I just need the array

Upvotes: 0

Views: 687

Answers (1)

lazizanie
lazizanie

Reputation: 514

this.specialRange = this.specialDates.map(ag => ag.range)

Upvotes: 1

Related Questions