Page 1 of 1

Filter array by multiple keys

Posted: Sun Jul 04, 2021 4:09 am
by stam
Hi all,
I know this works:

Code: Select all

filter elements of tArray where each["key"] is "xyz"
However i don't know if it's possible to filter by several keys?
When trying to filter an array checking a value in 2 different keys, this does not work:

Code: Select all

filter elements of tArray where each["key1"] = "xyz" or each["key2"] = "xyz"
Is it possible to do this? if so, what is the correct syntax?

Many thanks
Stam

Re: Filter array by multiple keys

Posted: Sun Jul 04, 2021 4:46 am
by rkriesel
stam wrote:
Sun Jul 04, 2021 4:09 am
Is it possible to do this? if so, what is the correct syntax?
Yes: yours.
At least, it works for me.

Code: Select all

on mouseUp
   local t
   put "xyz" into t[1]["key1"]
   put "abc" into t[2]["key1"]
   put "xyz" into t[3]["key2"]
   filter elements of t where each["key1"] = "xyz" or each["key2"] = "xyz"
   breakpoint
end mouseUp
How'd you get it to fail?
-- Dick

Re: Filter array by multiple keys

Posted: Sun Jul 04, 2021 12:37 pm
by stam
Hrmph… well in actuality the code in my app was searching for 3 keys “not empty”. Mind u late night coding, may have done something silly.
Will have a go again when back from work..,.

Re: Filter array by multiple keys

Posted: Sun Jul 04, 2021 8:50 pm
by stam
rkriesel wrote:
Sun Jul 04, 2021 4:46 am
Yes: yours.
How'd you get it to fail?
yep confirmed... me doing silly stuff at 3 am... ignore ;)