# listOf get index numbers

**URL:** <https://discuss.kotlinlang.org/t/listof-get-index-numbers/30699>\
**Category:** Android\
**Created:** [August 13, 2025, 4:12pm UTC](https://discuss.kotlinlang.org/t/listof-get-index-numbers/30699 "2025-08-13T16:12:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mynixmail.fever](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mynixmail.fever](https://discuss.kotlinlang.org/u/mynixmail.fever)\
**Post date:** [August 13, 2025, 4:12pm UTC](https://discuss.kotlinlang.org/t/listof-get-index-numbers/30699/1 "2025-08-13T16:12:36Z")

</div>

I am following this tutorial [here](https://www.youtube.com/watch?v=saKrGCWlJDs).

```auto
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val people = listOf("John", "Jack", "DJ", "Luke", "Matt", "Andrew", "Dave", "Steven", "Billy", "Zane", "Bobby", "Ryan", "Martin", "Werner", "Peter")

        setContent {
            RSSReaderTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )

                    LazyColumn {
                        items(people) {
                            ListItem(it)
                        }
                    }
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    RSSReaderTheme {
        Greeting("Android")
    }
}

@Composable
fun ListItem(name: String) {    
    Card(modifier = Modifier.fillMaxSize().padding(12.dp)) {
        Text(text = name, modifier = Modifier.padding(24.dp))
    }
}

```

What I want to do is the following:

Inside the ListItem function I want to also display (print) the index number of the “people” list.

For an example:

0 John

1 Jack

2 DJ

As I understand lists (arrays), the index of “John” will be 0, the index of “Andrew” will be 5, the index of “Ryan” will be 11.

```auto
@Composable
fun ListItem(name: String) {
    //print the index number of "name" on the l/h side of "Text"
    Card(modifier = Modifier.fillMaxSize().padding(12.dp)) {
        Text(text = name, modifier = Modifier.padding(24.dp))
    }
}

```

---

<div class="post-metadata">

**Author:** ![madmax1028](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/madmax1028/32/3335_2.png) [@madmax1028](https://discuss.kotlinlang.org/u/madmax1028)\
**Post date:** [August 13, 2025, 5:44pm UTC](https://discuss.kotlinlang.org/t/listof-get-index-numbers/30699/2 "2025-08-13T17:44:33Z")

</div>

You mean something like this?

```kotlin
items(people.withIndex()) { (index, value) ->
    ListItem("$index $value")
}

```

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [August 13, 2025, 5:45pm UTC](https://discuss.kotlinlang.org/t/listof-get-index-numbers/30699/3 "2025-08-13T17:45:27Z")

</div>

A quick search reveals the `itemsIndexed` [function](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#(androidx.compose.foundation.lazy.LazyListScope).itemsIndexed(kotlin.collections.List,kotlin.Function2,kotlin.Function2,kotlin.Function3)):

```kotlin
LazyColumn {
    itemsIndexed(people) { index, item ->
        ListItem("$index: $item")
    }
}

```
