How to replace all defined values ​​in an object with unknown structure with others?

  • 0
    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

  • 2 Answers
  • 0
    function walkRecursive(val, callback) {

    if (val instanceof Object) {
    Object.values(val).forEach(n => walkRecursive(n, callback));

    walkRecursive(obj, x => x && x.touched === true && (x.touched = false));
    Emma Dyer

  • 0
    iterate over the object recursively and update the desired properties
    Carter Warren

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!