From a334b2b30e3c72df68bf13c73b6f4e271a03c8b9 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 16 Jun 2017 10:36:40 +0200 Subject: [PATCH] Created a clean object function --- assets/js/common/utils.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index bc4c0a57..0458e532 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -52,6 +52,34 @@ function emptyElem(container){ return true; } +/** + * Delete all the content of an object + * + * @param {Object} object The object to clear + * @return {Boolean} True for a success + */ +function clearObject(object){ + + //Variable (for loop) is specific to this local scop + var i = 0; + + //Process each node of the object + for(i in object){ + + //Check if the node is an object + if(object[i].toString() === "[object Object]"){ + clearObject(object[i]); //Delete object content + console.log("Hello world"); + } + + //Delete node + delete object[i]; + } + + //Success + return true; +} + /** * Check a given email address *