4.22 select only indexed variables from an expression

use indets with type 'indexed'

expr:=16*a[3]+6*a[1]; 
terms:=indets(expr,'indexed'); 
 
         terms := {a[1], a[3]} 
 
#to find maximum index, then do 
 
map(x->op(x),terms) 
 
      {1, 3}