Here is the code :

```
for (i = 0; i < data.RecruitingGroups.length; i++) {
        data.RecruitingGroups[i].id = i;

        if (data.RecruitingGroups[i].Rule.Rules != null) {
            for (j = 0; j < data.RecruitingGroups[i].Rule.Rules.length; i++) {
                data.RecruitingGroups[i].Rule.Rules[j].id = j;
            }    
        } 
    }

```

Problem is that sometimes RecruitingGroups[].Rule is null. So I tried to verify it was not null before continuing and running the next for loop, but it still throws the error:

Uncaught TypeError: Cannot read property 'Rules' of null

How can i bypass this error.