Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
btpoole
Channel Surfer

Check Value roArray

Is there a quick way to check for a value in a roArray? Something like in_array?
0 Kudos
4 REPLIES 4
Komag
Roku Guru

Re: Check Value roArray

Not that I know of - you just have to search it.
FUNCTION in_array(theArray, value)
FOR EACH i IN theArray
IF Type(i) = Type(value) AND i = value THEN RETURN TRUE
END FOR
RETURN FALSE
END FUNCTION
0 Kudos
btpoole
Channel Surfer

Re: Check Value roArray

Much appreciated, thought maybe Brightscript had a function but yours works very well. Thanks again.
0 Kudos
EnTerr
Roku Guru

Re: Check Value roArray

A better idea would be to add to ifArray:

Index(x as Dynamic) as Integer
Return the index in the list of the first item whose value is x, -1 if not found

(All implementors of ifArray already do ifArrayGet/ifArraySet - also Delete() is harmonious on integer indexing)

If having to check a long (>100) list though, suggest using a dictionary lookup (i.e. ifAssociativeArray.doesExist(), .lookup() ).

By the way @RokuKC - any chance of fixing the equality/inequality operators, so that they don't puke "Type Mismatch"? I.e. "=" to return True only when both type and value of the arguments match - and False otherwise. Fair and square, no warnings no nothing - it's already the case in all script languages i can think of (python, javascript, lua, whathaveyou...)
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Check Value roArray

Hi @Enterr, those are good suggestions, and will be taken into consideration if/when possible. 🙂
0 Kudos