0

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

5
  • can you try this and see what does it display? this.specialRange = [...this.specialDates] Commented Feb 15, 2021 at 8:28
  • 4
    this.specialRange = this.specialDates.map(ag => ag.range) Commented Feb 15, 2021 at 8:30
  • How is this.specialDates initialized? Is it async? Commented Feb 15, 2021 at 8:32
  • @lazizanie That works thank you, And it get initialized on fetch Commented Feb 15, 2021 at 8:34
  • @lazizanie post as answer to get credits. Commented Feb 15, 2021 at 9:42

1 Answer 1

1

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

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

Comments

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.