Beautiful Codeblock

by

Pretty codeblocks ❤️‍🔥

File: DeepClone.ts

typescript
const deepClone = (obj: any) => {
	if (obj === null)
		return null;
	const clone = { ...obj };

	Object.keys(clone).forEach(
		(key) => {
			clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key];
		}
	);
	return Array.isArray(obj) && obj.length
		? (clone.length = obj.length) && Array.from(clone)
		: Array.isArray(obj)
			? Array.from(obj)
			: clone;
};

-END-

Early Access

We share our learnings and insights on our newsletter. We also provide weekly insights on AI progress and new tools.

By signing up, you agree to our privacy policy.