Finding Duplicate on a for loop

Finding Duplicate on a for loop

Hi, I'm trying to find a duplicate on a for loop on an index. but getting error. Please help me 
    x = Employee[ID != null && Status == "Active"];
4    y = Time_Log[Employee.ID == x && T_Date == "14 Jun 2023" && T_Date != null].Employee.Name.getAll();
5    newy2 = y.tolist(",");
6    for each index idx in newy2
7    {
8        prev2 = idx - 1;
9        previdx1 = newy2.getasstring(idx);
10        previdx2 = newy2.getasstring(prev2);
11        if(previdx1.contains(previdx2))
12        {
13            info "duplicate";
14        }
15    }
16}