--- id: json-arrays title: "JSON Arrays" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JSON arrays", "JSON array literal", "array in JSON", "arrays in objects", "loop JSON array"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "json", "arrays"] raw_sources: ["https://www.w3schools.com/js/js_json_arrays.asp"] applied_in: [] github_commit: "" --- # [[JSON Arrays]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) JSON arrays are square-bracket literals almost identical to JavaScript arrays β€” but their values are restricted to string, number, object, array, boolean, or null β€” accessed by index and commonly nested inside objects. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Array literals live inside JSON strings** β€” a JSON string can hold a JSON array literal such as `["Ford", "BMW", "Fiat"]`. [S1] - **Almost the same as JS arrays** β€” arrays in JSON are almost the same as arrays in JavaScript. [S1] - **Restricted value types** β€” in JSON, array values must be of type string, number, object, array, boolean, or null; in JavaScript they can additionally be any valid JS expression, including functions, dates, and undefined. [S1] - **Index access** β€” you access array values by index (`myArray[0]`). [S1] - **Arrays nest in objects** β€” objects can contain arrays, accessed like `myObj.cars[0]`. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Literal or parse** β€” `myArray = [...]` or `myArray = JSON.parse(myJSON)`. [S1] - **Index access** β€” `myArray[0]`, `myObj.cars[0]`. [S1] - **Two loop forms** β€” `for...in` over indices, or a classic counting `for` loop using `.length`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **JSON array literals** This is a JSON string: [S1] ```json ["Ford", "BMW", "Fiat"] ``` Inside the JSON string there is a JSON array literal: [S1] ```json ["Ford", "BMW", "Fiat"] ``` Arrays in JSON are almost the same as arrays in JavaScript. In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined. [S1] **JavaScript arrays** You can create a JavaScript array from a literal: [S1] ```javascript myArray = ["Ford", "BMW", "Fiat"]; ``` You can create a JavaScript array by parsing a JSON string: [S1] ```javascript myJSON = '["Ford", "BMW", "Fiat"]'; myArray = JSON.parse(myJSON); ``` **Accessing array values** You access array values by index: [S1] ```javascript myArray[0]; ``` **Arrays in objects** Objects can contain arrays: [S1] ```json { "name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"] } ``` You access array values inside an object by index: [S1] ```javascript myObj.cars[0]; ``` **Looping through an array** You can access array values by using a for-in loop: [S1] ```javascript for (let i in myObj.cars) { x += myObj.cars[i]; } ``` Or you can use a for loop: [S1] ```javascript for (let i = 0; i < myObj.cars.length; i++) { x += myObj.cars[i]; } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) Applied examples on the page: create an array from a literal and from `JSON.parse()`; access by index; embed an array in an object and read `myObj.cars[0]`; and iterate with both for-in and a counting for loop. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Parse a JSON array and index it: ```javascript myJSON = '["Ford", "BMW", "Fiat"]'; myArray = JSON.parse(myJSON); myArray[0]; ``` Loop an array nested in an object: ```javascript for (let i = 0; i < myObj.cars.length; i++) { x += myObj.cars[i]; } ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) JSON array values vs JavaScript array values: [S1] - **JSON** β€” values restricted to string, number, object, array, boolean, or null. - **JavaScript** β€” all of the above plus any valid JS expression, including functions, dates, and undefined. - **Loop choice** β€” `for...in` iterates indices succinctly; a counting `for` loop with `.length` gives explicit index control. The source presents both as valid alternatives without preferring one. ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript JSON Objects]], [[JavaScript JSON Parse]], [[JavaScript JSON Data Types]], [[JavaScript JSON]] - **μ°Έμ‘° λ§₯락:** Referenced whenever reading or iterating array data within parsed JSON. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JSON Arrays β€” https://www.w3schools.com/js/js_json_arrays.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JSON Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).