function walkNested(val, callback) {
callback(val);
if (val instanceof Object) {
Object.values(val).forEach(n => walkNested(n, callback));
}
}
walkNested(obj, n => n?.touched === true && (n.touched = false));
function walkNested(val, callback) {
for (const stack = [ val ]; stack.length;) {
const n = stack.pop();
callback(n);
stack.push(...Object.values(n ?? {}));
}
}