How to create and clone a JSON object?

后端 未结 8 743
独厮守ぢ
独厮守ぢ 2020-12-13 18:04

I was wondering how can I create a JSON (JS) object and then clone it.

8条回答
  •  眼角桃花
    2020-12-13 18:20

    This is what I do and it works like a charm

    if (typeof JSON.clone !== "function") {
        JSON.clone = function(obj) {
            return JSON.parse(JSON.stringify(obj));
        };
    }
    

提交回复
热议问题