Note: object contains other references, so cannot do as described in duplicate.
Let's say I have a large object, such as described in How to delete an object in JavaScript?. If we have the following object then:
s = Set;
s.add(otherSet); // we also have other references to these elements
s.add(otherObject);
// ...
deleteObjectAndAllReferences(s);
How would the function be structured such that it deletes the object and any references that it contains, recursively. I would guess it starts out as, but I think the 'delete' method/operator isn't always the same between different object types.
function deleteObjectAndAllReferences(obj) {
// do we only need to grab enumerable properties, or all?
for (elem of obj)
(typeof elem === 'object')? deleteObjectAndAllReferences(elem) : obj.remove(s);
}