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[@] Your question and answer will appear on and help other developers.

Related Questions & Answers