I'm trying to change an specific value in a nested key value structure, but when I set a value it changes all key's value.
Initial data is:
const data = {
"1.157685561": {
"1222344": {
"batb": [
[0, 0],
[0, 0],
[0, 0]
],
"batl": [
[0, 0],
[0, 0],
[0, 0]
]
},
"1222345": {
"batb": [
[0, 0],
[0, 0],
[0, 0]
],
"batl": [
[0, 0],
[0, 0],
[0, 0]
]
}
}
}
I want to change the value of an specific path
data['1.157685561']['1222344']['batl'][0] = [1,2]
But the result is wrong. Because it changes:
data['1.157685561']['1222344']
data['1.157685561']['1222345']
Final result:
{
"1.157685561": {
"1222344": {
"batb": [
[0, 0],
[0, 0],
[0, 0]
],
"batl": [
[1, 2],
[0, 0],
[0, 0]
]
},
"1222345": {
"batb": [
[0, 0],
[0, 0],
[0, 0]
],
"batl": [
[1, 2],
[0, 0],
[0, 0]
]
}
}
}
Source code: https://playcode.io/301552?tabs=console&script.js&output