Fix finding an element by index in array