How can I run through three separate arrays in the same for loop?

前端 未结 6 1311
遇见更好的自我
遇见更好的自我 2020-12-06 13:38

I have three arrays I am trying to run through and I want to use the values from all three arrays in one function. This might sound confusing but here is what I have:

<
6条回答
  •  时光说笑
    2020-12-06 14:13

    If you are always sure the arrays will be equal in length, then you are better to just loop through one of the arrays and use it's index to reference the others:

    for (index, name) in enumerate(Name) {
        makeUser(name, userAge: Age[index], userGender: Gender[index])
    }
    

    However, I would recommend getting this data into a dictionary, but I assume this is just sample data to illustrate a point. :)

提交回复
热议问题