How to replace all defined values in an object with unknown structure with others?
-
Tell me how to replace absolutely all touched: true properties with touched: false properties in an object that can have different nesting and structure?JavaScript Holden Dunn, May 1, 2019
-
function walkRecursive(val, callback) {
callback(val);
if (val instanceof Object) {
Object.values(val).forEach(n => walkRecursive(n, callback));
}
}
walkRecursive(obj, x => x && x.touched === true && (x.touched = false));Emma Dyer -
iterate over the object recursively and update the desired propertiesCarter Warren
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!