@@ -0,0 +1,66 @@
+<header>
+ HTML Tree
+</header>
+
+<body>
+ <script>
+ function walker(parent) {
+ let str = "";
+ let tagName = parent.tagName;
+ if (tagName) {
+ str = `<${tagName}`;
+ let attrs = parent.attrs;
+ if (attrs) {
+ for (const attrName in attrs) {
+ str += ` ${attrName}=${attrs[attrName]}`;
+ }
+ str += '>';
+ for (const child of parent.children) {
+ str += walker(child) //вложенный вызов - вложенный уровень вложенности :-D
+ str += `</${tagName}>`;
+ else {
+ str = parent;
+ return str;
+ const table = {
+ tagName: 'table',
+ attrs: {
+ border: "1",
+ },
+ children: [
+ {
+ tagName: 'tr',
+ tagName: "td",
+ children: ["1x1"],
+ children: ["1x2"],
+ ]
+ children: ["2x1"],
+ children: ["2x2"],
+ document.write(walker(table)); //вернет <table border='1' ....
+ </script>
+</body>
@@ -0,0 +1,70 @@
+ DOM Tree
+ let res = undefined;
+ res = document.createElement(tagName);
+ res[attrName] = attrs[attrName];
+ let childRes = walker(child)
+ if (typeof childRes === "object") {
+ res.append(childRes);
+ res.innerText = childRes;
+ res = parent;
+ return res;
+ document.body.append(walker(table)); //вернет <table border='1' ....
@@ -0,0 +1,68 @@
+ let isObject = true;
+ if (Array.isArray(parent)) {
+ res = [];
+ else if (parent != null && typeof parent === "object") {
+ res = {};
+ isObject = false;
+ if (isObject) {
+ for (el in parent) {
+ res[el] = walker(parent[el]);
+ // 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) //аналогично