Selecting all composite rois in roiManager

I am writing JavaScript. I have trace rois and composite rois in the roiManager. I want to split the composite rois. I tried a for loop but that didn’t work because it stops as soon as it comes to a roi that is not a composite. Is there a way to select all rois of type=composite?

There is an API method available which gives you the type of a selected ROI:


whereat Composite ROI’s are of type 9: