Open In App

How to get Array Structure with alert() in JavaScript?

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
8 Likes
Like
Report

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:

Approach 1: Using arrayName.toString() method

  • First, take the values in a variable(let arr).
  • Pass the array name in the alert().
  • We can directly use the array name because arrayName is automatically converted to arrayName.toString()

Example 1: This example follows the approach discussed above.

Output:

output

Approach 2: Using join() method

  • First take the values in a variable(lets arr).
  • Pass the array name in the alert() .
  • We can use.join() method for our simplicity to see the array elements each in a line.

Example: This example follows the approach discussed above.

Output:

output

Similar Reads