mapIndexedTo
Applies the given transform function to each element and its index in the original array and appends the results to the given destination.
@IgnorableReturnValueinline fun <T, R, C : MutableCollection<in R>> Array<out T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C(source)
val words = arrayOf("apple", "banana", "cherry")
val result = mutableListOf<String>().apply {
words.mapIndexedTo(this) { index, word ->
"$index: $word"
}
}
println(result) // Output: [0: apple, 1: banana, 2: cherry]