forEachIndexed

Performs the given action on each element, providing sequential index with the element.

inline fun <T> Array<out T>.forEachIndexed(action: (index: Int, T) -> Unit)(source)
val colors = arrayOf("Red", "Green", "Blue")

colors.forEachIndexed { index, color ->
    println("Color at index $index is $color")
}

Source