Remove function properties from object (Deep/Recursive)

Code Snippets 4 U
const removeObjectFunctionProps = <T>(obj: any): T => {
	if (!obj || typeof obj !== 'object') {
		return obj;
	}
	const props = Object.keys(obj);
	for (const prop of props) {
		if (typeof obj[prop] === 'function') {
			delete obj[prop];
		}
		if (typeof obj[prop] === 'object') {
			removeObjectFunctionProps(obj[prop]);
		}
	}
	return obj;
};

Leave a Reply

Your email address will not be published. Required fields are marked *

seven + three =