Change one of the values in the same object in js, that is, change the address of the object, so as not to affect each other

The case is as follows:

 let     pro = {

                      inParams:{

                         "ip":'',  

                      }

                  }

          var  proLeft = pro, proRight = JSON.parse(JSON.stringify(pro))

            proLeft.inParams.ip = leftIp

            proRight.inParams.ip = rightIp

In this way, if the value of the ip attribute is changed, the two objects will not affect each other.

The reason is the pointing problem of the object address, just change the address pointing of one of the objects.

Guess you like

Origin blog.csdn.net/weixin_43703816/article/details/127371180