cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
miguello
Level VII

How to make Associative Array to return key value for non-existing key?

Folks, 

 

Is there any way to make a default value in associated array dynamic?

Meaning that if you try to access a key that does not exist, it returns not a static default value, but some lambda function, for instance - the key itself? Or key*2, or key||"_string".

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to make Associative Array to return key value for non-existing key?

I don't think you can make the returned value dynamic. You could use Try(), but I think a function could be better option to handle the missing values

Names Default To Here(1);
ex = Associative Array({"red", "blue"}, {1, 2});

Try(ex["green"], "green");
-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: How to make Associative Array to return key value for non-existing key?

I don't think you can make the returned value dynamic. You could use Try(), but I think a function could be better option to handle the missing values

Names Default To Here(1);
ex = Associative Array({"red", "blue"}, {1, 2});

Try(ex["green"], "green");
-Jarmo

Recommended Articles