In an array of objects, you know one value of one of the objects and how to modify the other values of that object.

if an array is known

items: [
    {name: "zhangsan",
     score: 0
    },
    {name: "lisi",
     score: 0
    }
],

in a form, the select tag binds the input box corresponding to items.name, and the variable value changingScore
when name is selected as "zhangsan" in the select drop-down menu, how can
add changingScore to items [0] .score after submission?

it"s best not to use for loops, because there may be a lot of data in the array

Mar.11,2021

then you can save the currently selected index value in a hidden input [id= "selectIndex"]. When select is selected, the selected index is stored in the hidden input, and then when submitted, set it directly through index,

.
// 
document.querySelector("-sharpselectIndex").value = index;
let index = parseInt(document.querySelector("-sharpselectIndex"));
items[index].score = changingScore;

or store the selected value in localStorage or sessionStorage. The idea is to store, update and maintain an index value.

Menu