So I've got an object called "options" with these items in it:
var options = {
assignments: ['involved', 'assignee', 'candidate'],
assignment: ""
}
With a for loop, I'm trying to put the values from my array assignments in the assignment var, one by one. Then I'm using "options" with the new value as parameters for another function I'm calling inside my loop.
for (var i = 0; i < options.data.assignments.length; i++) {
options.data.assignment = options.data.assignments[i];
console.log("value of i : ",i);
console.log("value of options :",options);
otherFunction(options);
}
I was expecting to see results like this :
value of i : 0
value of options : {assignment = "involved"...}
value of i : 1
value of options : {assignment = "assignee"...}
value of i : 2
value of options : {assignment = "candidate"...}
But instead I have something like this :
value of i : 0
value of options : {assignment = "candidate"...}
value of i : 1
value of options : {assignment = "candidate"...}
value of i : 2
value of options : {assignment = "candidate"...}
The thing is while doing that my assignment variable is always set to "candidate", the value at the end of my array.
The strange thing is when I'm trying to console.log(options.data.assignments[i])
, the right value shows up. Same for the "i", it goes from 0 to 1 then 2 and stops properly. So my loop is working perfectly fine, except when I want to set the value of my variable.
Any ideas what's the problem here?
Thanks