
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript JSON Arrays
Arrays in JSON are similar to Arrays in JavaScript. JavaScript JSON arrays looks like this −
let obj = { name:'Rohan', sports : ['cricket','Football','volleyball','hockey'] }
Following is the code for JSON arrays in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JSON arrays</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to access JSON array </h3> <script> let sampleEle = document.querySelector(".sample"); let obj = { name:'Rohan', sports : ['cricket','Football','volleyball','hockey'] } document.querySelector(".Btn").addEventListener("click", () => { obj.sports.forEach(item=>{ sampleEle.innerHTML += item + '<br>'; }) }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Converting two arrays into a JSON object in JavaScript
- JavaScript: create an array of JSON objects from linking two arrays
- JavaScript JSON HTML
- How can we merge two JSON arrays in Java?
- Convert JSON array into normal json in JavaScript
- Remove json element - JavaScript?
- JavaScript JSON parse() Method
- Convert JSON to another JSON format with recursion JavaScript
- How to convert JSON text to JavaScript JSON object?
- Javascript typed arrays
- JSON. stringify( ) function in JavaScript
- Formatting dynamic json array JavaScript
- Deep Search JSON Object JavaScript
- Regroup JSON array in JavaScript
- JSON group object in JavaScript

Advertisements