Shallow-clone an ES6 Map or SetHow to shallow copy a Set in JavaScript?What is the most efficient way to deep clone an object in JavaScript?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How do I loop through or enumerate a JavaScript object?How do I correctly clone a JavaScript object?Set a default parameter value for a JavaScript functionHow can I display a JavaScript object?Convert form data to JavaScript object with jQueryParse JSON in JavaScript?Copy array by value

What can a novel do that film and TV cannot?

What is exact meaning of “ich wäre gern”?

Apex Sleep: what is CPU penalty

Is it possible that Curiosity measured its own methane or failed doing the spectrometry?

In the Seventh Seal why does Death let the chess game happen?

What happens if the limit of 4 billion files was exceeded in an ext4 partition?

Platform Event Design when Subscribers are Apex Triggers

Are "confidant" and "confident" homophones?

Contributing to a candidate as a Foreign National US Resident?

Why did moving the mouse cursor cause Windows 95 to run more quickly?

What is the fundamental difference between catching whales and hunting other animals?

Did Snape really give Umbridge a fake Veritaserum potion that Harry later pretended to drink?

how can i make this execution plan more efficient?

Implementing absolute value function in c

How to deal with administrative duties killing the research spirit?

How to travel between two stationary worlds in the least amount of time? (time dilation)

What is the difference between a historical drama and a period drama?

What are the differences of checking a self-signed certificate vs ignore it?

Does a multiclassed wizard start with a spellbook?

What is this arch-and-tower near a road?

Do I need to be legally qualified to install a Hive smart thermostat?

How to deal with a Murder Hobo Paladin?

List comprehensions in Mathematica?

Show that there are infinitely more problems than we will ever be able to compute



Shallow-clone an ES6 Map or Set


How to shallow copy a Set in JavaScript?What is the most efficient way to deep clone an object in JavaScript?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How do I loop through or enumerate a JavaScript object?How do I correctly clone a JavaScript object?Set a default parameter value for a JavaScript functionHow can I display a JavaScript object?Convert form data to JavaScript object with jQueryParse JSON in JavaScript?Copy array by value






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








66















How do you shallow-clone an ES6 Map or Set object?



I want to get a new Map or Set that has the same keys and values.










share|improve this question




























    66















    How do you shallow-clone an ES6 Map or Set object?



    I want to get a new Map or Set that has the same keys and values.










    share|improve this question
























      66












      66








      66


      9






      How do you shallow-clone an ES6 Map or Set object?



      I want to get a new Map or Set that has the same keys and values.










      share|improve this question














      How do you shallow-clone an ES6 Map or Set object?



      I want to get a new Map or Set that has the same keys and values.







      javascript ecmascript-6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 3 '15 at 16:47









      Jo LissJo Liss

      16k10 gold badges92 silver badges139 bronze badges




      16k10 gold badges92 silver badges139 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          139














          Use the constructor to clone Maps and Sets:



          var clonedMap = new Map(originalMap)

          var clonedSet = new Set(originalSet)





          share|improve this answer


















          • 1





            How to do a deep clone?

            – BILL
            Apr 29 '16 at 11:34






          • 3





            Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

            – Patrick Hund
            Feb 24 '17 at 13:23






          • 3





            Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

            – user6445533
            Feb 25 '17 at 20:55






          • 3





            Unfortunately the copy constructor does not work in IE 11 (empty map is created).

            – Jan Molnar
            Jan 17 '18 at 12:10










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30626070%2fshallow-clone-an-es6-map-or-set%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          139














          Use the constructor to clone Maps and Sets:



          var clonedMap = new Map(originalMap)

          var clonedSet = new Set(originalSet)





          share|improve this answer


















          • 1





            How to do a deep clone?

            – BILL
            Apr 29 '16 at 11:34






          • 3





            Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

            – Patrick Hund
            Feb 24 '17 at 13:23






          • 3





            Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

            – user6445533
            Feb 25 '17 at 20:55






          • 3





            Unfortunately the copy constructor does not work in IE 11 (empty map is created).

            – Jan Molnar
            Jan 17 '18 at 12:10















          139














          Use the constructor to clone Maps and Sets:



          var clonedMap = new Map(originalMap)

          var clonedSet = new Set(originalSet)





          share|improve this answer


















          • 1





            How to do a deep clone?

            – BILL
            Apr 29 '16 at 11:34






          • 3





            Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

            – Patrick Hund
            Feb 24 '17 at 13:23






          • 3





            Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

            – user6445533
            Feb 25 '17 at 20:55






          • 3





            Unfortunately the copy constructor does not work in IE 11 (empty map is created).

            – Jan Molnar
            Jan 17 '18 at 12:10













          139












          139








          139







          Use the constructor to clone Maps and Sets:



          var clonedMap = new Map(originalMap)

          var clonedSet = new Set(originalSet)





          share|improve this answer













          Use the constructor to clone Maps and Sets:



          var clonedMap = new Map(originalMap)

          var clonedSet = new Set(originalSet)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 3 '15 at 16:47









          Jo LissJo Liss

          16k10 gold badges92 silver badges139 bronze badges




          16k10 gold badges92 silver badges139 bronze badges







          • 1





            How to do a deep clone?

            – BILL
            Apr 29 '16 at 11:34






          • 3





            Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

            – Patrick Hund
            Feb 24 '17 at 13:23






          • 3





            Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

            – user6445533
            Feb 25 '17 at 20:55






          • 3





            Unfortunately the copy constructor does not work in IE 11 (empty map is created).

            – Jan Molnar
            Jan 17 '18 at 12:10












          • 1





            How to do a deep clone?

            – BILL
            Apr 29 '16 at 11:34






          • 3





            Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

            – Patrick Hund
            Feb 24 '17 at 13:23






          • 3





            Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

            – user6445533
            Feb 25 '17 at 20:55






          • 3





            Unfortunately the copy constructor does not work in IE 11 (empty map is created).

            – Jan Molnar
            Jan 17 '18 at 12:10







          1




          1





          How to do a deep clone?

          – BILL
          Apr 29 '16 at 11:34





          How to do a deep clone?

          – BILL
          Apr 29 '16 at 11:34




          3




          3





          Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

          – Patrick Hund
          Feb 24 '17 at 13:23





          Check out this fiddle to see how to deep clone a map: jsfiddle.net/pahund/5qtt2Len/1

          – Patrick Hund
          Feb 24 '17 at 13:23




          3




          3





          Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

          – user6445533
          Feb 25 '17 at 20:55





          Map should be treated as an abstract data type, not as a Javascript object. Hence deep cloning a Map doesn't make sense.

          – user6445533
          Feb 25 '17 at 20:55




          3




          3





          Unfortunately the copy constructor does not work in IE 11 (empty map is created).

          – Jan Molnar
          Jan 17 '18 at 12:10





          Unfortunately the copy constructor does not work in IE 11 (empty map is created).

          – Jan Molnar
          Jan 17 '18 at 12:10








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30626070%2fshallow-clone-an-es6-map-or-set%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?