I think this will cause an error if `instanceIndex` is actually `undefined`. A safe way is:

```javascript
if (typeof instanceIndex !== 'undefined') ...
```