I have a use-case where I want list of keys from a map to be presented in dropdown.
I have created a map using a transformer, and using it's value in another transformer.
I can see it is a map, but isn't giving out keys (or values) when trying to use Object.keys({{transformer1.value}}) (or Object.values).
If you are trying to get the values of the keys (e.g. 9:00am to 4:00pm) in the drop down then you need to do a little more work:
Object.keys(pairs).map( key => pairs[key] )
Object.keys(object) will return the keys of the object as an array -- but you really want the value of those keys (not the key literal). By mapping (essentially looping over the array of keys) you can access the value from the original object.
I am planning to do this using labels and values of a dropdown, (will put '9:00am to 4:00pm' in label and '2' in value).
But the thing that I wanted to know is why is Object.keys not working if I am using value of another transformer, when it's working perfectly fine for a variable initialised here itself.
I am not 100% sure I understand how you are trying to use this data in the other location. However, in your example of trying to populate a drop down box with the values from the map if you use:
Object.keys(object)
The return of that will be an array [] with the values in that array equal to the 'names' of the keys in the original object (e.g. in your case [1,2].
If you are interested in populating a selection list with the values of those keys (and the the names of the keys themselves) -- you would need to do something similar to what I was suggesting: