1 Answers
The index method is used to print both value and index numbers in an array. Let’s see one example.
Code:
fun main(args : Array<String>){
var nums = listOf(1,2,3,4)
for((i,e) in nums.withIndex())
{
println(” $i : $e”)
}
}
This code prints both Index and value.
Output:
0 : 1
1 : 2
2 : 3
3 : 4