자바스크립트에서 Json 형태의 object 변수인 person이라는 변수가 있다.
💻 예제 코드
<html>
<body>
</body>
<script>
const person = {};
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";
console.log("객체 출력"+ person);
</script>
</html>
person에 어떤 값이 들어있나 보려고 console.log를 찍어보니
[object Object]
이렇게 나온다.
그럴 땐, person을 JSON.stringify으로 감싸준다.
console.log(JSON.stringify(person));
[출력 결과값]
{"firstName":"John","lastName":"Doe","age":50,"eyeColor":"blue"}
짝짝짝
반응형
'Programming > 삽질기록' 카테고리의 다른 글
PostgreSQL 데이터베이스 생성 (feat.Dbeaver) (0) | 2025.02.04 |
---|---|
이미 사용 중인 포트 / address already in use :::3000 해결법 (0) | 2024.11.25 |
Apexchart 데이터 0일때 차트에 나타내기/감추기(chart show/hide) (2) | 2024.10.17 |
스프링부트 SecureRandom 예제 (0) | 2023.11.20 |
[Git] Another git process seems to be running in this repository : 에러해결 (0) | 2023.08.11 |