Home > Software design >  Property not updaated in Angular Component when reversing array
Property not updaated in Angular Component when reversing array

Time:12-19

I have an Angular Component which has a public array variable initialized to [] . In the constructor I am getting a response from a service and updating the array using this.variable = array.reverse(). But this doesn't store the reversed array rather the original one. Anything I am missing. Thanks in advance.

CodePudding user response:

You need to change the reference to the array, so try

this.variable = [...array].reverse()

CodePudding user response:

you have missed () to reverse() method try this.variable = array.reverse()

  • Related