0

i have this object:

enter image description here

and i want to update each student on object, each student is with an unique index (id from database), so i can send that object to the server later, this is how i´ve tried:

studentID = param (integer)
notes = param (object)

the function is call every time i change an input in the form

for (let i = 0; i < this.studentNotes[studentID].desempenos.length; i++) {
    if (this.studentNotes[studentID].desempenos[i].desempeno === desempeno) {
        this.studentNotes[studentID].desempenos[i].nota = notes.nota;
    }
}

The problem is this: I enter the values for the index 190 and it saves, but when i want to save the values for other index, let's say 191, it overrides the value from 190.

i can't figure it out why.

Thanks in advance.

Andres Felipe
  • 4,292
  • 1
  • 24
  • 41
  • `desempenos[i].nota = notes.nota` it should be one reference, try `Object.entries(notes.nota).forEach(item => { this.studentNotes[studentID].desempenos[i].nota[item[0]] = item[1]})` – Sphinx Aug 02 '18 at 22:41
  • hi, notes is an object passed like a param. i updated my question – Andres Felipe Aug 02 '18 at 23:11
  • 1
    check this [Javascript Reference vs value](https://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language) – Sphinx Aug 02 '18 at 23:20
  • wow didn't know about this, thanks man – Andres Felipe Aug 03 '18 at 00:06

0 Answers0