Javascript - How to clone an object?

前端 未结 8 1926
悲&欢浪女
悲&欢浪女 2021-02-18 22:28

I am confused. I create a copy from myObjOne, than i delete an entry from myObjOne and JS delete the entry in my copy(myObjTwo) too? But w

8条回答
  •  孤街浪徒
    2021-02-18 22:56

    With ES6, use the spread operator.

    myObjTwo = {...myObjOne}
    

    The spread operator in es6 is just an ellipsis. It creates a copy of the original, even if the original is destroyed

提交回复
热议问题