1

I have a class that has objects and members. After a successful operation, I want to reset all the members of the class. Is there a way to achieve this without writing a for loop? I cannot set the class object to null, as it will break processing downstream.

for( var member in this.myService)
    {
      member = "";
    }

But when it encounters another object it fails. I will have to go through the members of that object, instead of that is there a way to reset all the members that belong in this class to "". Most members are strings, and the inner objects members are also string.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
KudmiSubba
  • 59
  • 2
  • 9
  • Possible duplicate of [How do I loop through or enumerate a JavaScript object?](https://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object) – Igor Feb 28 '18 at 21:08
  • `Is there a way to achieve this without writing a for loop` <= You have to either write code to empty out each property/field explicitly **or** you have to create a loop that iterates over the objects properties. – Igor Feb 28 '18 at 21:10
  • Sir, Thank you. I had something like that in mind. My question was , if there was a command in angular that would , clear out the object. The other challenge is, I have to cast and check if every object is not a string with the === and then loop through that object and clear it. I will try to do that and get back to you. Thank you for your help. – KudmiSubba Mar 01 '18 at 15:03

0 Answers0