How to view array of a structure in JavaScript ? Last Updated : 23 Jan, 2023 Comments Improve Suggest changes Like Article Like Report The Javascript arrays are heterogeneous. The structure of the array is the same which is enclosed between two square brackets [ ], and the string should be enclosed between either "double quotes" or 'single quotes'. You can get the structure of by using JSON.stringify() or not, here you will see the use of JSON.stringify(). For other procedure, you can check this link. Syntax: JSON.stringify(value, replacer, space) The Functionality of the alert() is to first give information to the user before gets proceeding further. So, in the below code, the button on the click function(Alert()) has two alerts (alert()), after displaying all the alerts it gets further with the webpage. By clicking ‘ok’ in the alert box it displays the next alert until all are done. Let's check the type of alerts that can be applied: alert(JSON.stringify(guardians)): It displays as is array structure.alert(JSON.stringify(guardians, 9, 1)): It displays the customized structure, where the 9 acts as a replacer, makes array elements get printed in vertically, and 1 acts as a space number and provides one space between elements.alert(JSON.stringify(guardians, "", 5)): It displays, the customized structure, where the "" acts as a replacer, makes array elements get printed vertically, and 5 acts as a space number and provides five spaces between elements. Example 1: HTML <h1 style="color:Green;"> GeeksforGeeks </h1> <h3> Getting array structure JSON.stringify </h3> <p id="d1"></p> <input type="button" onclick="Alert()" value="Click Here" /> <script> function Alert() { // Array structure var guardians = ["Quill", "Gamora", "Groot", "Rocket", "Drax", 21]; // Prints the array elements with a comma // separated but not the structure document.getElementById("d1").innerHTML = "Guardians = " + guardians; // Alerts the window with the array alert(JSON.stringify(guardians)) // Alerts the window with a customized array alert(JSON.stringify(guardians, 9, 1)) } </script> Output: How to view array of a structure in JavaScript ? Example 2: You can also get the structure of an Associate array easily. html <!DOCTYPE html> <html> <head> <title> How to view array of a structure in JavaScript? </title> </head> <body style="text-align:center;"> <h1 style="color:Green;"> GeeksforGeeks </h1> <h3> Getting associate array structure JSON.stringify </h3> <p id="d1"></p> <input type="button" onclick="Alert()" value="Click Here" /> <script> function Alert() { // Array structure var guardians = { "Newton": "Gravity", "Albert": "Energy", "Edison": "Bulb", "Tesla": "AC" }; // Alerts the window with the array alert(JSON.stringify(guardians)) // Alerts the window with a // customized array alert(JSON.stringify(guardians, 9, 1)) // Alerts the window with a // customized array alert(JSON.stringify(guardians,"",5)) } </script> </body> </html> Output: How to view array of a structure in JavaScript ? Comment More infoAdvertise with us Next Article How to view array of a structure in JavaScript ? T Tejashwi5 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies JavaScript-Questions Similar Reads How to get Array Structure with alert() in JavaScript? To display an array structure using alert() in JavaScript, the array can be converted into a string format Array.toString(). This allows the contents of the array to be shown in a readable format within an alert box.Below are the approaches to get array structure with alert() in JavaScript: Table of 2 min read How to store a key=> value array in JavaScript ? In JavaScript, storing a key-value array means creating an object where each key is associated with a specific value. This allows you to store and retrieve data using named keys instead of numeric indices, enabling more intuitive access to the stored information.Here are some common approaches:Table 4 min read How to Access Array of Objects in JavaScript ? Accessing an array of objects in JavaScript is a common task that involves retrieving and manipulating data stored within each object. This is essential when working with structured data, allowing developers to easily extract, update, or process information from multiple objects within an array.How 4 min read How to work with Structs in JavaScript ? Structs are typically found in languages like C, C++, and similar, and they provide a way to organize related data items under one name. Typically JavaScript does not have built-in support for structs, but you can achieve similar functionality using objects. Objects in JavaScript are dynamic collect 4 min read How to Store an Object Inside an Array in JavaScript ? Storing an object inside an array in JavScript involves placing the object as an element within the array. The array becomes a collection of objects, allowing for convenient organization and manipulation of multiple data structures in a single container. Following are the approaches through which it 3 min read How to Recursively Build a JSON Tree Structure in JavaScript ? To create a JSON tree structure recursively in JavaScript we need to create a recursive function that traverses the data and constructs the tree. We can create a JSON tree structure recursively in JavaScript using the below methods. Table of Content Using Arrays to build a JSON tree structure Using 4 min read How to Convert Object to Array in JavaScript? In this article, we will learn how to convert an Object to an Array in JavaScript. Given an object, the task is to convert an object to an Array in JavaScript. Objects and Arrays are two fundamental data structures. Sometimes, it's necessary to convert an object to an array for various reasons, such 4 min read How to print a circular structure in a JSON like format using JavaScript ? The circular structure is when you try to reference an object which directly or indirectly references itself. Example: A -> B -> A OR A -> A Circular structures are pretty common while developing an application. For Example, suppose you are developing a social media application where each u 4 min read Set to Array in JS or JavaScript This article will show you how to convert a Set to an Array in JavaScript. A set can be converted to an array in JavaScript in the following ways:1. Using Spread OperatorThe JavaScript Spread Operator can be used to destructure the elements of the array and then assign them to a new variable in the 2 min read How to use forEach with an Array of Objects in JavaScript ? Using the forEach() method with an array of objects in JavaScript is essential for iterating over collections and performing operations on each object. This guide explores effective techniques to utilize forEach() for array manipulation, enhancing your coding skills. Syntax: array.forEach( function( 3 min read Like