Jump to content

Object and Array cloning in Javascript


fanThomas

Recommended Posts

I needed to clone an array so that i could reuse its original content later, however the program din't work correctly, the original was always destroyed. I used a simple assignement as it works fine in PHP. Researching on the internet for the problem I found that Objects in Javascript are assigned by reference always.On W3schools i did't found any hint about this important behaviour difference to other languages, neither in the tutorial nor in the reference. I suggest therefore to loose a word anywhere about this, best in all concerned Objects as Arrays, Date Objects and Javascript Objects. This would help new programmes to better understand the Javascript concept and save lot of time for bug fixing.Also an example how to best clone an Array or other Object would be greatly appreciated since it is not easy to do this in Javascript.I love to use W3schools and I use it always for reference when I'm programming. Especially the examples on your pages are very helpful. Many times I could simulate the problem solving before i used it in my programs. Thank you for this very helpful tutorial and reference.Thomas Jakober

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...