How to show a value from array that relates to the value of another array, javascript

后端 未结 6 1116
轻奢々
轻奢々 2021-01-28 19:39

I am trying to have the name show up with the score that relates to that name. So if the highest score is 98 I want Joels name to show up in the display where is says name here.

6条回答
  •  不知归路
    2021-01-28 20:10

    You have the i value (the positioning of the score in scores array). This i value corresponds with the person in the persons array. Use this i value to select the person.

    To make stuff easier you could use an object to associate name (string) with score (int) like:

     var test = {"Ben": 88, "Joel": 98, "Judy": 77, "Anne": 88}
    

    Then you would need to modify the for loop.

提交回复
热议问题