--- 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 + "
"; } ``` **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 + "
"; } ``` 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).