cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to move from signal modeling to system modeling at the first JMP Aerospace Analytics webinar. Register. June 18, 1 p.m. US Eastern Time.

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