# Handle missing array values

**URL:** <https://discuss.hail.is/t/handle-missing-array-values/2022>\
**Category:** Hail Query & hailctl\
**Created:** [April 26, 2021, 5:18pm UTC](https://discuss.hail.is/t/handle-missing-array-values/2022 "2021-04-26T17:18:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NLSVTN](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/nlsvtn/32/339_2.png) [@NLSVTN](https://discuss.hail.is/u/NLSVTN)\
**Post date:** [April 26, 2021, 5:18pm UTC](https://discuss.hail.is/t/handle-missing-array-values/2022/1 "2021-04-26T17:18:21Z")

</div>

I have such code:

```
hl.struct(**{'AC': nisc[mt.row_key].info.AC[mt.a_index-1],
             'AF': nisc[mt.row_key].info.AF[mt.a_index-1]})

```

That fails with `index out of bounds` error if `nisc[mt.row_key].info.AC` does not have correct length that should be `>= mt.a_index`. What I need is something like:

`nisc_ac = nisc[mt.row_key].info.AC[mt.a_index-1] if hl.len(nisc[mt.row_key].info.AC) >= mt.a_index else null`

or

`nisc_ac = hl.if_else(hl.len(nisc[mt.row_key].info.AC) >= mt.a_index, nisc[mt.row_key].info.AC[mt.a_index], hl.missing(hl.tint32))`

But none of the two are working. Need a way to handle missing values upon array access, I think.

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [April 26, 2021, 5:32pm UTC](https://discuss.hail.is/t/handle-missing-array-values/2022/2 "2021-04-26T17:32:51Z")

</div>

Your last example should work, but should just be `>` not `>=`. You can only index up to length - 1 .

---

<div class="post-metadata">

**Author:** ![NLSVTN](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/nlsvtn/32/339_2.png) [@NLSVTN](https://discuss.hail.is/u/NLSVTN)\
**Post date:** [April 26, 2021, 5:49pm UTC](https://discuss.hail.is/t/handle-missing-array-values/2022/3 "2021-04-26T17:49:35Z")

</div>

Yeah, just off by one error. Thanks a lot!
