9609c04755
W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더). - Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외) - Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체) - Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속) 각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
185 lines
6.5 KiB
Markdown
185 lines
6.5 KiB
Markdown
---
|
|
id: javascript-object-display
|
|
title: "JavaScript Object Display"
|
|
category: "Frontend"
|
|
status: "draft"
|
|
verification_status: "conceptual"
|
|
canonical_id: ""
|
|
aliases: ["JS object display", "object Object", "JSON.stringify", "Object.values", "Object.entries", "for in loop", "display object"]
|
|
duplicate_of: ""
|
|
source_trust_level: "B"
|
|
confidence_score: 0.89
|
|
created_at: 2026-06-23
|
|
updated_at: 2026-06-23
|
|
review_reason: ""
|
|
merge_history: []
|
|
tags: ["javascript", "js", "web", "frontend", "w3schools", "objects", "display", "json"]
|
|
raw_sources: ["https://www.w3schools.com/js/js_object_display.asp"]
|
|
applied_in: []
|
|
github_commit: ""
|
|
---
|
|
|
|
# [[JavaScript Object Display]]
|
|
|
|
## 🎯 한 줄 통찰 (One-line insight)
|
|
Displaying a JavaScript object directly outputs `[object Object]`; to show its data, name the properties, loop over them, or convert the object with `Object.values()`/`Object.entries()`/`JSON.stringify()`. [S1]
|
|
|
|
## 🧠 핵심 개념 (Core concepts)
|
|
- **Direct display gives `[object Object]`** — this appears when you insert an object where a string is expected. [S1]
|
|
- **Name the properties** — properties can be concatenated into a string by name. [S1]
|
|
- **Loop with `for...in`** — collect property values in a loop, using `person[x]` (not `person.x`). [S1]
|
|
- **`Object.values()`** — creates an array from the property values. [S1]
|
|
- **`Object.entries()`** — makes it simple to use objects in loops as `[key, value]` pairs. [S1]
|
|
- **`JSON.stringify()`** — converts an object to a JSON-notation string; built in and supported in all browsers. [S1]
|
|
|
|
## 🧩 추출된 패턴 (Extracted patterns)
|
|
- **`for...in` with bracket access** — `text += person[x]` works because `x` is the loop variable holding the key. [S1]
|
|
- **Values-to-string** — `Object.values(person).toString()` flattens values into a comma-joined string. [S1]
|
|
- **Destructured entries loop** — `for (let [fruit, value] of Object.entries(fruits))` iterates key/value pairs. [S1]
|
|
|
|
## 📖 세부 내용 (Details)
|
|
**How to Display JavaScript Objects?**
|
|
Displaying a JavaScript object will output `[object Object]`. [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
name: "John",
|
|
age: 30,
|
|
city: "New York"
|
|
};
|
|
|
|
let text = person;
|
|
```
|
|
|
|
**Why do I See [object Object]?**
|
|
`[object Object]` appears when you attempt to insert an object (a data structure containing properties) into a context where a string is expected; it represents how JavaScript handles this situation. Solutions include displaying the object properties by name, in a loop, via `Object.values()`, or via `JSON.stringify()`. [S1]
|
|
|
|
**Displaying Object Properties**
|
|
The properties of an object can be added in a string: [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
name: "John",
|
|
age: 30,
|
|
city: "New York"
|
|
};
|
|
|
|
// Add Properties
|
|
let text = person.name + "," + person.age + "," + person.city;
|
|
```
|
|
|
|
**Using a For .. In Loop**
|
|
The properties of an object can be collected in a loop: [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
name: "John",
|
|
age: 30,
|
|
city: "New York"
|
|
};
|
|
|
|
// Build a Text
|
|
let text = "";
|
|
for (let x in person) {
|
|
text += person[x] + " ";
|
|
};
|
|
```
|
|
You must use `person[x]` in the loop. `person.x` will not work, because `x` is the loop variable. [S1]
|
|
|
|
**Using Object.values()**
|
|
`Object.values()` creates an array from the property values: [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
name: "John",
|
|
age: 30,
|
|
city: "New York"
|
|
};
|
|
|
|
// Create an Array
|
|
const myArray = Object.values(person);
|
|
|
|
// Stringify the Array
|
|
let text = myArray.toString();
|
|
```
|
|
|
|
**Using Object.entries()**
|
|
`Object.entries()` makes it simple to use objects in loops: [S1]
|
|
```javascript
|
|
const fruits = {Bananas:300, Oranges:200, Apples:500};
|
|
|
|
let text = "";
|
|
for (let [fruit, value] of Object.entries(fruits)) {
|
|
text += fruit + ": " + value + "<br>";
|
|
}
|
|
```
|
|
|
|
**Using JSON.stringify()**
|
|
JavaScript objects can be converted to a string with the JSON method `JSON.stringify()`. `JSON.stringify()` is included in JavaScript and supported in all browsers. The result is a string written in JSON notation: [S1]
|
|
```javascript
|
|
{"name":"John","age":50,"city":"New York"}
|
|
```
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
name: "John",
|
|
age: 30,
|
|
city: "New York"
|
|
};
|
|
|
|
// Stringify Object
|
|
let text = JSON.stringify(person);
|
|
```
|
|
|
|
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
|
|
| Technique | Output shape | Use when |
|
|
| --- | --- | --- |
|
|
| Property by name | Hand-built string | You know the exact properties [S1] |
|
|
| `for...in` loop | Concatenated values | Iterate all properties generically [S1] |
|
|
| `Object.values()` | Array of values | You only need the values [S1] |
|
|
| `Object.entries()` | `[key, value]` pairs | You need both keys and values in a loop [S1] |
|
|
| `JSON.stringify()` | JSON-notation string | Serialize the whole object [S1] |
|
|
|
|
## 🛠️ 적용 사례 (Applied in summary)
|
|
The page's own snippets are the canonical applied examples — the `[object Object]` pitfall, property-by-name concatenation, the `for...in` loop, `Object.values().toString()`, the `Object.entries()` destructured loop, and `JSON.stringify(person)`. No external project/commit applications found in the source.
|
|
|
|
## 💻 코드 패턴 (Code patterns)
|
|
For...in loop (note bracket access):
|
|
```javascript
|
|
let text = "";
|
|
for (let x in person) {
|
|
text += person[x] + " ";
|
|
};
|
|
```
|
|
Entries loop with destructuring:
|
|
```javascript
|
|
for (let [fruit, value] of Object.entries(fruits)) {
|
|
text += fruit + ": " + value + "<br>";
|
|
}
|
|
```
|
|
Serialize to JSON:
|
|
```javascript
|
|
let text = JSON.stringify(person);
|
|
```
|
|
|
|
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
|
No contradictions found in the source.
|
|
|
|
## ✅ 검증 상태 및 신뢰도
|
|
- **상태:** draft
|
|
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
|
|
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
|
- **신뢰 점수:** 0.89
|
|
- **중복 검사 결과:** 신규 생성 (New discovery)
|
|
|
|
## 🔗 지식 그래프 (Knowledge Graph)
|
|
- **상위/루트:** [[JavaScript Tutorial]]
|
|
- **관련 개념:** [[JavaScript Objects]], [[JavaScript Object Properties]], [[JavaScript Object Methods]]
|
|
- **참조 맥락:** Referenced whenever rendering object data to the page or serializing it for transport.
|
|
|
|
## 📚 출처 (Sources)
|
|
- [S1] W3Schools — JavaScript Object Display — https://www.w3schools.com/js/js_object_display.asp
|
|
|
|
## 📝 변경 이력 (Change history)
|
|
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Object Display" page (Astra wiki-curation, P-Reinforce v3.1 format).
|