Skip to content

Instantly share code, notes, and snippets.

@brenopolanski
Created August 25, 2014 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenopolanski/2eb29e354627aae5a4f3 to your computer and use it in GitHub Desktop.
Save brenopolanski/2eb29e354627aae5a4f3 to your computer and use it in GitHub Desktop.
Delete object function
var obj = {
a: 'house',
b: function() {
console.log('Hi function');
},
c: 123456
}
deleteObjectFunction: function(obj) {
if (obj.length === undefined) {
$.each(obj, function(key, val) {
if (typeof(val) === 'function') {
delete(obj[key]);
}
});
}
else {
for (var i = 0, len = obj.length; i < len; i++) {
$.each(obj[i], function(key, val) {
if (typeof(val) === 'function') {
delete(obj[i][key]);
}
});
}
}
return obj;
}
deleteObjectFunction(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment