The question is pretty self-explanatory; I want to be able to check if an associative array contains a value I'm about to (potentially) insert, before I actually insert it. Is there a simple way to do this without searching through dict.keys
? Maybe something like if (dict.contains(val)) ...
?
To test if a key is in an associative array, use the in
operator:
string[int] aa;
string* ps = 100 in aa;
if(ps)
{
// 100 is a key in aa, ps is a pointer to the corresponding value
}
else
{
// 100 is not a key in aa
}
To test if a value exists, you'll have to search through aa.values
.
if (!dict.get(key, null))
dict[key] = val;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With