1

I am trying to get the index of a specific value in an array of maps.

the map is getting data from a data class so when I try to get the index it wants all the values of the map instead of me being able to ask for the index based on one value.

Here is the array of maps.

var skillsListMain = arrayListOf(SkillsSelectPost("Drawing Experience",
    "0", "Select", "0"),(SkillsSelectPost("Running Experience",
    "0", "Select", "0"),

and my SkillsSelect Post

data class SkillsSelectPost(

var name: String,
var On: String,
var level: String,
var sel: String
)

I am trying to use

val name = skill["name"]!!
val index = skillsListMain.indexOf(name)

But it makes me use

  val name = skill["name"]!!
  val index = skillsListMain.indexOf(SkillsSelectPost(name, "", "", "")

1 Answer 1

5

I don't see any map here. I see list of object (SkillsSelectPost). So, if you want to take specific item index by name, maybe try:

val name = "Drawing Experience"
val item = skillsListMain.find { it.name == name } 
val index = skillsListMain.indexOf(item)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the reply on this, it has worked for what I wanted, I have it wrong in my head, I thought I had created an array of maps thinking that a map is the same as a dictionary in swift programming, I am trying to learn Kotlin after learning swift and trying to get the same results. thinking that creating the object was the same as a map. I have much more to learn, and I presume the same in swift.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.