Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

remove repeating objects in the array

Hello, I want to remove the repeating objects in roArray. How can we do that?
ex if i have a array:{
"A"
"B"
"C"
"A"
"B"
"C"
"A"
"B"
}

my output array should be like:
{
A, B, C
}

Thanks,
Pradeep
0 Kudos
1 Reply
Level 8

Re: remove repeating objects in the array

There's no built-in way to do that, but you can write a simple loop and keep track of what items you've seen with an associative array. Something like this:


function RemoveDups(array as Object) as Object
out = []
seen = {}
for each item in array
if seen[item] = invalid then
out.Push(item)
seen[item] = true
end for
return out
end function


I haven't tested this, it might require some tweaking.

--Mark
0 Kudos