I want to pass the current ‘this’ context to a for loop which could iterate over an array.
I have this code for example:
someArray : [] = [];
this.service.user.isAworking ? this.someArray.push ({key:'A', value: 'Yes'}) : ({key:'A', value: 'No'})
this.service.user.isBworking ? this.someArray.push ({key:'B', value: 'Yes'}) : ({key:'B', value: 'No'})
this.service.user.isCworking ? this.someArray.push ({key:'C', value: 'Yes'}) : ({key:'C', value: 'No'})
this.service.user.isDworking ? this.someArray.push ({key:'D', value: 'Yes'}) : ({key:'D', value: 'No'})
this.service.user.isEworking ? this.someArray.push ({key:'E', value: 'Yes'}) : ({key:'E', value: 'No'})
isAworking,isBworking,isCworking etc are properties of this.user.
These properties could be extended later, let’s say till isZworking.
Now, if I have to simplify the above code and put in a forEach loop? What would the way be?
I believed creating an array of the properties (isAworking,isBworking,isCworking etc) and iterating them over the values of “Key” in the object stored in an array, but I’m unable to reach a working code.
Example:
propertiesArray = ['.isAworking', '.isBworking', '.isCworking', ......]
keyArray = ['A' , 'B', 'C' ......]
Problem is when I try to put them in a loop and iterate like:
this.service.user + propertiesArray[0];
This appends it like a string and the answer I get is:
[object][object]’.isAworking’
How do I pass the context? Tried call(), bind(), apply() but I’m unable to get it correct.