Index variable takes up log(n) space?
If you have a variable $x$ that can represent any number from $0$ to $n-1$ (or any value from a set of of $n$ possible values, really), such an the index of an array of $A[0 \dots n-1]$ of $n$ elements, then $x$ needs to use at least $\lceil \log_2 n \rceil = \Omega(\log n)$ bits.
This is because there are $2^b$ combinations for the values of $b$ bits. Then, to represent $n$ values you need to have $2^b \ge n$, i.e., $b \ge \log_2 n$. You can add the ceiling since $b$ must be an integer.
When you say &quot;an array of $n$ elements uses $O(n)$ space&quot; you are probably  thinking of a word-RAM model. Here the memory is split into addressable words, i.e., groups of $w$ bits. Each entry in the array occupies one (or a constant number of) words of memory (this also means that the elements in the array can't represent more than $2^{\Theta(w)}$ values each).
Usually the word size $w$ is chosen to be $\Theta(\log n)$, where $n$ is some natural parameter of the input problem (e.g., the size of the instance). In this case an index of an array of $n$ elements can be stored into a single memory word, i.e., in $O(1)$ space.
However this is not contradicting the above lower bound of $\lceil \log_2 n \rceil$ bits, it's just that these bits are all packed into a single (or into a constant number of) memory word(s).