How do I correctly clone a JavaScript object?

Posted by Editorial Staff | Updated on

Use the following JavaScript code to clone a JavaScript object to other object.

If you do not use Dates, functions, undefined, regExp or Infinity within your object, a very simple one liner is JSON.parse(JSON.stringify(object)):


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers