You can find the index of an element through a linear or binary search. A linear search is a function in which you LOOP through each and EVERY element of an array until it finds the match of the desired element. When it finds the matching element, it returns the index. Therefore time COMPLEXITY of the linear search is O(n). Linear search can be APPLIED to sorted as WELL as an unsorted array.
If the array is sorted, you can use a binary search that repeatedly splits the array in half until the median of the interval matches the desired element and returns the index. Therefore time complexity of the binary search is O(log n).