<header> Deep Copy </header> <body> <script> function walker(parent) { let res = undefined; let isObject = true; if (Array.isArray(parent)) { res = []; } else if (parent != null && typeof parent === "object") { res = {}; } else { res = parent; isObject = false; } if (isObject) { for (el in parent) { res[el] = walker(parent[el]); } } return res; } const table = { tagName: 'table', attrs: { border: "1", }, children: [ { tagName: 'tr', children: [ { tagName: "td", children: ["1x1"], }, { tagName: "td", children: ["1x2"], }, ] }, { tagName: 'tr', children: [ { tagName: "td", children: ["2x1"], }, { tagName: "td", children: ["2x2"], }, ] } ] } // document.body.append(walker(table)); //вернет <table border='1' .... const arr = [1, "string", null, undefined, { a: 15, b: 10, c: [1, 2, 3, 4], d: undefined, e: true }, true, false] const arr2 = walker(arr) //arr2 и все его вложенные массивы и объекты - другие объекты, которые можно менять без риска поменять что-то в arr const table2 = walker(table) //аналогично </script> </body>