Tinderbox v9 Icon

Dictionary.keys


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Property   [other Property type actions]

 Item   [operators of similar scope]

 Dictionary, Set & List operations   [other Dictionary, Set & List operations operators]

 9.0.0

 


Dictionary.keys

A List-type property. Returns a list of unsorted key names (i.e. only the keys' strings and not those of values) for this note. Unlike a List or Set, the Dictionary cannot be iterated directly using .each(). Instead, Dictionary.keys provides an iter-able list. so

$MyDictionary.keys.each(x){
	if($MyDictionary[x] == "Whoops"){
		 ...
	}
}

Therefore do not try: $MyDictionary.each(x)

A dictionary cannot be sorted but as above Dictionary.keys can be sorted. This is the previous example above, but with an added .sort operator inserted after .keys:

$MyDictionary.keys.sort.each(x){
	if($MyDictionary[x] == "Whoops"){
		 ...
	}
}

Note that when iterating a dictionary with .each(X) the loop variable X is the String value of the key.

Depending on your needs you might prefer to pass the dictionary explicitly to a list attribute before doing further work:

$MyList = $MyDictionary.keys;

// work with MyList