indices

Returns an IntRange of the valid indices for the children of this view group.

This can be used for looping:

for (i in viewGroup.indices.reversed) {
if (viewGroup[i] is SomeView) {
viewGroup.removeViewAt(i)
}
}

Or to determine if an index is valid:

if (2 in viewGroup.indices) {
// Do something…
}