I can’t understand why my variable change
if(chat.users[i + 1])
console.log("1: " + chat.users[i + 1].username);
if(save[i+1])
console.log("2: " + save[i + 1].username);
chat.users[i + 1] = save[i];
if(chat.users[i + 1])
console.log("3: " + chat.users[i + 1].username);
if(save[i+1])
console.log("4: " + save[i + 1].username);
I have
1: test1
2: test1
3: test
4: test
I can’t understand why I don’t have
1: test1
2: test1
3: test
4: test1
Thanks
Edit: The all code is there
http://codepaste.net/gi5ghf
(line 92)
Now with your code it’s clear! Let’s have a look at it
What?
Let me explain it to you again. For example you got this:
Now you write this:
Maybe you wanted to copy a to b but you ONLY created a reference!
So have a look at this:
So if you change one value of the object or array it’ll be changed for the other one too because it’s only a reference and they both got the same memory address.
If you really Want to clone/copy the object/array then have a look at this question.