JavaScript | JSON Arrays Last Updated : 28 May, 2021 Comments Improve Suggest changes Like Article Like Report The JSON Arrays is similar to JavaScript Arrays. Syntax of Arrays in JSON Objects: // JSON Arrays Syntax { "name":"Peter parker", "heroName": "Spiderman", "friends" : ["Deadpool", "Hulk", "Wolverine"] } Accessing Array Values: The Array values can be accessed using the index of each element in an Array. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="paraId"></p> <script> var spidermanDetail = { "name": "Peter parker", "heroName": "Spiderman", "friends": ["Deadpool", "Hulk", "Wolverine"] }; var x = spidermanDetail.friends[0]; document.getElementById("paraId").innerHTML = x; </script> </body> </html> Output: Deadpool Looping over an Array: The for-in loop can be used for iterating through Array. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="paraId"></p> <script> var str = ""; var spidermanDetail = { "name": "Peter parker", "heroName": "Spiderman", "friends": ["Deadpool", "Hulk", "Wolverine"] }; for (i in spidermanDetail.friends) { str += spidermanDetail.friends[i] + "<br/>"; } document.getElementById("paraId").innerHTML = str; </script> </body> </html> Output: Deadpool Hulk Wolverine Modifying an Array Values: An index number can be used for the modification of values. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="paraId"></p> <script> var str = ""; var spidermanDetail = { "name": "Peter parker", "heroName": "Spiderman", "friends": ["Deadpool", "Hulk", "Wolverine"] }; spidermanDetail.friends[1] = "Iron Man"; for (i in spidermanDetail.friends) { str += spidermanDetail.friends[i] + "<br/>"; } document.getElementById("paraId").innerHTML = str; </script> </body> </html> Output: Deadpool Iron Man Wolverine Deleting Array Values: The values of an Array can be deleted using delete keyword. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="paraId"></p> <script> var str = ""; var spidermanDetail = { "name": "Peter parker", "heroName": "Spiderman", "friends": ["Deadpool", "Hulk", "Wolverine"] }; delete spidermanDetail.friends[2]; for (i in spidermanDetail.friends) { str += spidermanDetail.friends[i] + "<br/>"; } document.getElementById("paraId").innerHTML = str; </script> </body> </html> Output: Deadpool Hulk Nested Arrays in JSON Objects: In the nested array, another array can also be a value of an array. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="paraId"></p> <script> var str = ""; var spidermanDetail = { "name": "Peter parker", "heroName": "Spiderman", "friends": [{ "heroName": "Deadpool", "skills": ["Martial artist", "Assassin"] }, { "heroName": "Hulk", "skills": ["Superhuman Speed", "Superhuman Strength"] }, { "heroName": "Wolverine", "skills": ["Retractable bone claws", "Superhuman senses"] }] }; for (i in spidermanDetail.friends) { str += "<h3>" + spidermanDetail.friends[i].heroName + "</h3>"; for (j in spidermanDetail.friends[i].skills) { str += spidermanDetail.friends[i].skills[j] + "<br/>"; } } document.getElementById("paraId").innerHTML = str; </script> </body> </html> Output: Comment More infoAdvertise with us Next Article JavaScript | JSON Arrays L letsLearnCode Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript JSON JSON (JavaScript Object Notation) is a lightweight data format for storing and exchanging data. It is widely used to send data between a server and a client. JSON is simple, language-independent, and easy to understand.JSON stands for JavaScript Object Notation.It is a lightweight, text-based data i 4 min read Javascript | JSON PHP JSON stands for the JavaScript Object Notation. It is used to exchanging and storing the data from the web-server. JSON uses the object notation of JavaScript. JavaScript objects can be converted into the JSON and receive JSON format text into the JavaScript objects. Converting the JavaScript object 7 min read JavaScript Array Exercise In JavaScript, an Array is a versatile data structure that allows you to store multiple values in a single variable. Arrays can hold different data types, including strings, numbers, objects, and even other arrays. JavaScript arrays are dynamic, which means they can grow or shrink in size.JavaScript 1 min read JavaScript JSON Parser JSON (JavaScript Object Notation) is a popular lightweight data exchange format for sending data between a server and a client, or across various systems. JSON data is parsed and interpreted using a software component or library called a JSON parser. Through the JSON parsing process, a JSON string i 3 min read Formatting Dynamic JSON array JavaScript Formatting a Dynamic JSON array is important because it organizes complex data structures, making them easier to read, manipulate, and communicate within applications and APIs. We will explore approaches to formatting dynamic JSON arrays in JavaScript. Below are the approaches to format dynamic JSON 2 min read JavaScript ES5 (JS 2009) JavaScript 2009 (ES5) refers to the fifth edition of the ECMAScript language specification, standardized in 2009. It introduced several features, like strict mode, new methods, JSON support, and improved syntax for better programming practices and compatibility across browsers. ECMAScript 5 (ES5) in 7 min read JavaScript JSON Objects JSON (JavaScript Object Notation) is a handy way to share data. It's easy for both people and computers to understand. In JavaScript, JSON helps organize data into simple objects. Let's explore how JSON works and why it's so useful for exchanging information.const jsonData = { "key1" : "value1", ... 3 min read JSON vs JavaScript Object JSON (JavaScript Object Notation) and JavaScript Objects are important for handling data in JavaScript, but they serve different purposes. JSON is a lightweight data format for transferring data, while JavaScript Objects are in-program data structures used for manipulation and logic.What is JSON?JSO 2 min read How to Parse JSON Data in JavaScript? To parse JSON data in JavaScript, you can use the JSON.parse() method. This method converts a JSON string into a JavaScript object, making it easier to work with the data.1. Parse Simple JSON StringsJavaScriptconst jsonS = '{"name": "Rahul", "age": 25, "city": "Mumbai"}'; const obj = JSON.parse(json 2 min read What is JSON Array? JSON Array is almost the same as JavaScript Array. JSON array can store values of type string, array, boolean, number, object, or null. In JSON array, values are separated by commas. Array elements can be accessed using the [] operator.JSON Array is of different types. Let's understand them with the 5 min read Like