
console.table(object) 함수는 객체를 테이블 형태로 출력할 때, 객체 안에 객체가 있는 경우 오류가 발생하는 이유는 객체 안에 객체가 있기 때문입니다.
객체 안에 객체가 있는 경우, console.table(object) 함수 내에서 객체를 배열로 변환하여 테이블 형태로 출력할 수 있습니다.
예를 들어, 다음과 같은 객체가 있다고 가정해 보겠습니다.
#hostingforum.kr
javascript
const object = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345'
}
};
이 객체를 테이블 형태로 출력하기 위해, 객체 안에 객체를 배열로 변환할 수 있습니다.
#hostingforum.kr
javascript
const object = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345'
}
};
const array = Object.keys(object.address).map(key => ({ key, value: object.address[key] }));
console.table(array);
이 코드는 객체 안에 객체를 배열로 변환하여 테이블 형태로 출력합니다.
또한, 객체 안에 객체가 있는 경우, console.table(object) 함수 내에서 객체를 JSON.stringify() 함수를 사용하여 문자열로 변환할 수 있습니다.
#hostingforum.kr
javascript
const object = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345'
}
};
console.log(JSON.stringify(object, null, 2));
이 코드는 객체를 JSON.stringify() 함수를 사용하여 문자열로 변환하여 테이블 형태로 출력합니다.
이러한 방법을 사용하여, 객체 안에 객체가 있는 경우 console.table(object) 함수 내에서 객체를 테이블 형태로 출력할 수 있습니다.
2025-03-09 15:32