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 2: You can also get the structure of an Associate array easily.