HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-26
1 <p>Для вывода вложенных объектов первого и второго уровня вложенности достаточно передавать их в console.log():</p>
1 <p>Для вывода вложенных объектов первого и второго уровня вложенности достаточно передавать их в console.log():</p>
2 const nestedObject = { firstLevel: { secondLevel: { someKey: 'someValue', anotherKey: 'anotherValue', }, }, }; console.log(nestedObject); /* =&gt; { firstLevel: { secondLevel: { someKey: 'someValue', anotherKey: 'anotherValue' } } } */<p>Но начиная с объектов третьего уровня вложенности, мы увидим следующее:</p>
2 const nestedObject = { firstLevel: { secondLevel: { someKey: 'someValue', anotherKey: 'anotherValue', }, }, }; console.log(nestedObject); /* =&gt; { firstLevel: { secondLevel: { someKey: 'someValue', anotherKey: 'anotherValue' } } } */<p>Но начиная с объектов третьего уровня вложенности, мы увидим следующее:</p>
3 const deepNestedObject = { firstLevel: { secondLevel: { thirdLevel: { fourthLevel: { someKey: 'someValue', anotherKey: 'anotherValue', }, }, }, }, }; console.log(deepNestedObject); // =&gt; { firstLevel: { secondLevel: { thirdLevel: [Object] } } }<p>Для вывода на экран вложенных объектов независимо от глубины вложенности их можно преобразовать в формат JSON с помощью метода JSON.stringify(), передав третьим аргументом количество пробелов для формирования отступов:</p>
3 const deepNestedObject = { firstLevel: { secondLevel: { thirdLevel: { fourthLevel: { someKey: 'someValue', anotherKey: 'anotherValue', }, }, }, }, }; console.log(deepNestedObject); // =&gt; { firstLevel: { secondLevel: { thirdLevel: [Object] } } }<p>Для вывода на экран вложенных объектов независимо от глубины вложенности их можно преобразовать в формат JSON с помощью метода JSON.stringify(), передав третьим аргументом количество пробелов для формирования отступов:</p>
4 console.log(JSON.stringify(deepNestedObject, null, 2)); /* =&gt; { "firstLevel": { "secondLevel": { "thirdLevel": { "fourthLevel": { "someKey": "someValue", "anotherKey": "anotherValue" } } } } } */
4 console.log(JSON.stringify(deepNestedObject, null, 2)); /* =&gt; { "firstLevel": { "secondLevel": { "thirdLevel": { "fourthLevel": { "someKey": "someValue", "anotherKey": "anotherValue" } } } } } */