cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
miguello
Level VI

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