I am looking for a way to use the same object repeatedly in JavaScript by emptying it after its purpose is served, without creating a new object each time. In arrays, I usually do arr.length=0
to clear an array instead of assigning it to a new memory location. Is there a similar method to empty an object in JavaScript?
Scenario:
var obj = {};
obj["name"]="Aman";
obj["country"]="India";
console.log(obj); // output is { name: 'Aman', country: 'India' }
Is there a way to reuse this obj after clearing its contents? If so, how can it be done?