Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6763907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:31:56+00:00 2026-05-26T14:31:56+00:00

I am confused. I create a copy from myObjOne , than i delete an

  • 0

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 why?

  myObjOne = {};
  myObjOne['name'] = 'xxx';
  myObjOne['id'] = 'yyy';
  myObjOne['plz'] = 'zzz';  

  // clone
  myObjTwo = myObjOne;

  // remove something
  delete myObjOne['name'];

  console.dir(myObjTwo);

example
http://jsbin.com/itixes/edit#javascript,html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:31:56+00:00Added an answer on May 26, 2026 at 2:31 pm

    Update: Removing Object.create as a method of cloning as indicated in comments.

      myObjTwo = myObjOne;
    

    does not clone. It simply copies the reference.

    If you want to clone, you can use JSON.parse and JSON.stringify

    var x = {a:{b:{c:{'d':'e'}}}};
    var y = JSON.parse(JSON.stringify(x));  //y is a clone of x
    console.log(y.a.b.c.d); //prints e
    console.log(y === x); //prints false
    

    Warning: As Raynos mentioned in comments, this JSON based clone does not retain methods of the input object in the output object. This solution is good enough if your object does not contain any methods. Methods are properties of a object that are functions. If var obj = {add : function(a,b){return a+b;}} then add is a method of obj.

    If you need a solution that supports copying of methods, then go through these SO answers (as pointed out by musefan, Matt and Ranhiru Cooray)

    • How do I correctly clone a JavaScript object?
    • What is the most efficient way to deep clone an object in JavaScript?

    I would suggest How do I correctly clone a JavaScript object?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This looks simple but I am confused: The way I create a vector of
I am confused as to when to create object instances or Static Helper classes.
I'm trying to create the IDL for the IConverterSession interface and I'm confused by
I'm confused as hell with all the bazillion ways to read/write/create excel files. VSTO,
I am a bit confused about socket programming in C. You create a socket,
I am confused about how to make a Form visible. When we create a
I am a little bit confused about 2 things. Firstly when I create an
Found myself quite confused today about this. I create a blank repository locally(hg init),
I'm trying to create some javascript code that will display a javascript form (from
Duplicate: Confused about hashes How can SHA encryption create unique 40 character hash for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.