Retrieve Index of Dictionary Key

I have a variable of type dictionary(string, int32). I want to retrieve the index of a key provided by the user. So if the userInput is “coffee” I want to retrieve the index (0) and if userInput is “tea” I want to retrieve index (1). I want it this way because I want to assign the index to a variable and use it to retrieve a key later in the workflow:

myDictonaryVariable = {{“coffee”, 3}, {“tea”,2}}`
userInput = “coffee”
myIndexVariable = Array.IndexOf(myDictionaryVariable.Keys.ToArray(),userInput)

assigns the index (0) to an int32 variable but is there a better, more direct way of doing this?

myDictionaryVariable.ElementAt(myIndexVariable).Key

returns the key “coffee”

Thank you!

@k-specs
Have a look here:
grafik

1 Like

@ppr
Thank you! Do wish there was a more direct route like Dictionary.IndexOf(userInput) available.

@k-specs
So maybe you will find a way by refering to the .Net API docu or other resources

1 Like