This seems odd to me, why not:

```javascript
if (!lastItem) {
  arr[arr.length - 1] = 1;
}
```