Skip to main content Accessibility Feedback

copy.js

Create an identical clone of an array or object.

Works in all modern browsers, and at least back to IE9.

/*!
 * Create an identical clone of an array or object
 * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
 * @param  {Array|Object} obj The array or object to copy
 * @return {Array|Object}     The clone of the array or object
 */
var copy = function (obj) {
	return JSON.parse(JSON.stringify(obj));
};