I am struggling to display a string array in a JavaScript alert popup. The goal is to show the string index or Serial Number, followed by a space and then a line break before displaying the value of each string in the array. Unfortunately, my current code is not functioning as expected.
function DisplayStrings(array)
{
for(var i = 0; i < array.length; i++)
alert(i+1 + ": " + array[i] + "\\n");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<button id="Submit">Submit</button>
</div>
C#:
protected void Submit_Click(object sender, EventArgs e)
{
string[] Str = new string[5];
Str[0] = "string1";
Str[1] = "string2";
Str[2] = "string3";
Str[3] = "string4";
Str[4] = "string5";
Submit.Attributes.Add("onclick", "javascript:DisplayStrings(Str);");
}
I want the output to be displayed in the following format:
1: string1
2: string2
3: string3
4: string4
5: string5
The JavaScript popup is currently not working. Any suggestions on how I can achieve this?