below is my code i am defining an object, and adding second and third keys to it. And at the end when i change the third key, it also changes the second key somehow, you can look results from browsers localstorage tab
window.onload = function() {
localStorage.clear();
const myObject = {
"1": {
keyframes: [
{"posX": "0", "posY": "0"},
{"posX": "150", "posY": "0"},
{"posX": "300", "posY": "0"}
]
}
}
// example keyframes for new object key
let example_keyframes = {
keyframes: [
{"posX": "0", "posY": "0"},
{"posX": "400", "posY": "0"},
{"posX": "100", "posY": "0"}
]
};
// adding new key(second) to my object
let lastkey = Object.keys(myObject)[Object.keys(myObject).length - 1] ;
myObject[parseInt(lastkey)+1] = example_keyframes;
window.localStorage.setItem("myObject", JSON.stringify(myObject));
// adding new key(third) to my object
lastkey = Object.keys(myObject)[Object.keys(myObject).length - 1] ;
myObject[parseInt(lastkey)+1] = example_keyframes;
window.localStorage.setItem("myObject", JSON.stringify(myObject));
// change third keys, keyframe value
myObject[3]['keyframes'][2]['posY'] = 12;
myObject[3]['keyframes'][2]['posX'] = 49;
window.localStorage.setItem("myObject", JSON.stringify(myObject));
}
i tried to shorten the code and reproduce the error and it's still valid.