I have a JSON object as follows. After sending ajax call I want to clear this. How I can do?
var cfamFwdDtls = {
cndtwizid: [],
clientIdsInstnIds: [],
positioncd: '',
positionCnt: '',
rcrtrInstnId: '',
positionLocation: {
cntryIdFrCndt: '',
stateIdFrCndt: '',
zipIdFrCndt: '',
cityIdFrCndt: ''
},
searchPstnSkill: []
};
If you want to reset the entire object, just reset the variable back to {}
;
cfamFwdDtls = {};
// or
cfamFwdDtls = new Object;
// will prevent garbage collection
delete cfamFwdDtls;
However, if you want a more fine-grained way of "resetting" the object, you are going to need to define what specifically your requirements for a reset are. Regardless, you can always iterate through the object and make the necessary objects.
for (var key in cfamFwdDtls) {
if (typeof cfamFwdDtls[key] == "string") {
cfamFwdDtls[key] = '';
} else if (Array.isArray(cfamFwdDtls[key])) {
cfamFwdDtls[key] = [];
} else {
delete cfamFwdDtls[key];
}
}
The above definition could be a possible way to define your particular situation since I only see strings and arrays in your object. If the key is neither of those, it would just delete the key. This could be tailored as you find necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With