Okay… there’s a lot to unpack here for someone who doesnt know the code, but…
If the filter is empty, simply don’t add it to finalData?
I feel like you’re vastly overcomplicating your effort here…I really really dislike saying this, but… what exactly are you trying to do with this function? What are your inputs, and your desired outputs?