Lets assume I have object such as;
var obj = {
name: "alex",
surname: "black",
age: 21,
grade: 14
}
I want to nullify all values as;
var obj = {
name: "",
surname: "",
age: 0,
grade: 0
}
How can I do this? I can look through keys by Object.keys(obj) and nullify each key according to their type.
Like;
var str ="";
for(var i =0; i < obj.length; i++){
if(type of obj[i] === "string")
str += Object.keys(obj)[i] + ': "",\n';
if(type of obj[i] === "integer")
str += Object.keys(obj)[i] + ': 0,\n';
}
Is it the proper way to do it?
edit: Thank you for your all answers. But this object can also contain objects. So I should loop through all the keys and nullify them as your example shows. Am I right?