How to copy/clone a hash/object in JQuery?

前端 未结 6 2161
既然无缘
既然无缘 2021-02-05 00:52

I have a simple object (or hash) in Javascript:

var settings = {
  link: \'http://example.com\',
  photo: \'http://photos.com/me.jpg\'
};

I nee

6条回答
  •  无人共我
    2021-02-05 01:40

    My 2 cents:

    function clone(hash) {
      var json = JSON.stringify(hash);
      var object = JSON.parse(json);
    
      return object;
    }
    

    It may not be the most optimized option but it can be handy for some scenarios.

提交回复
热议问题