Script issue with keeping certain labels

Dear good people,
I am trying to scriptify few processing steps. So in an image have several object segmented and labeled, then I measure properties of them. From that result table, I calculate the labels that meets certain measurement value for example “Perimeter”.

Now I need to generate new picture keeping only those labels.
In Fiji- morpholibj - label Images-label edition does similar things as a window comes to give labels need to keep.
In macro recorder I see the command as run("Select Label(s)", "label(s)=[1300, 1500, 1600]");

So in my macro scripting I am trying to add array str instead of [1300, 1500, 1600] as
str2 = "label(s)=["+str+ "]"; //str is the array as comma separated string arr = [1300, 1500, 1600] // run("Select Label(s)", str2);
but it does not work, giving array there also don’t work.

Can you suggest how can I add this in my script?

Welcome to the forum, @muntahi, and sorry for the delayed reply!

The following works for me (to select labels 31 and 202, for example):

str = "[31, 202]";
run("Select Label(s)", "label(s)="+str);

If the issue persists for you, can you share your entire script, so we can help debugging?

thank you very much, it was really helpful.
it solved the issue.