[javascript] Javascript Array Alert

Im new to Javascript.

Im trying to code these four buttons. I'm currently on the second one. I've coded an array. But when I click on the button, it replaces the page. I want to display the array in an alert box.

<html>
<head>
<script type="text/javascript">

function SayHello()
{
    alert("Hello World!");
}

function DumpCustomers()
{

    var aCustomers=new Array();
    aCustomers[0]="Frank Sinatra ";
    aCustomers[1]="Bob Villa ";
    aCustomers[2]="Kurt Cobain ";
    aCustomers[3]="Tom Cruise ";
    aCustomers[4]="Tim Robbins ";
    aCustomers[5]="Santa Claus ";
    aCustomers[6]="Easter Bunny ";
    aCustomers[7]="Clark Kent ";
    aCustomers[8]="Marry Poppins ";
    aCustomers[9]="John Wayne ";

    document.write(aCustomers[0]);
    document.write(aCustomers[1]);
    document.write(aCustomers[2]);
    document.write(aCustomers[3]);
    document.write(aCustomers[4]);
    document.write(aCustomers[5]);
    document.write(aCustomers[6]);
    document.write(aCustomers[7]);
    document.write(aCustomers[8]);
    document.write(aCustomers[9]);
}

function DisplayFishCounts()
{

}
function FindJonGalt()
{

}

</script>
</head>

<body>
<form name="Main">
<input type="button" id=1 onclick="SayHello();" value="Say Hi"/>
<input type="button" id=1 onclick="DumpCustomers();" value="Dump Customers"/>
<input type="button" id=1 onclick="DisplayFishCounts();" value="Display Fish Counts"/>
<input type="button" id=1 onclick="FindJonGalt();" value="Where is Jon Galt?"/>

</form>
</body>
</html>

This question is related to javascript arrays popup alert

The answer is


If you want to see the array as an array, you can say

alert(JSON.stringify(aCustomers));

instead of all those document.writes.

http://jsfiddle.net/5b2eb/

However, if you want to display them cleanly, one per line, in your popup, do this:

alert(aCustomers.join("\n"));

http://jsfiddle.net/5b2eb/1/


Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array? Simple Popup by using Angular JS how to make window.open pop up Modal? How to handle authentication popup with Selenium WebDriver using Java Show popup after page load How to make popup look at the centre of the screen? How to handle Pop-up in Selenium WebDriver using Java HTML / CSS Popup div on text click How to make a Div appear on top of everything else on the screen? Popup window in winform c# Display UIViewController as Popup in iPhone

Examples related to alert

Swift alert view with OK and Cancel: which button tapped? Bootstrap Alert Auto Close How to reload a page after the OK click on the Alert Page How to display an alert box from C# in ASP.NET? HTML - Alert Box when loading page How to show an alert box in PHP? Twitter Bootstrap alert message close and open again How to handle login pop up window using Selenium WebDriver? How to check if an alert exists using WebDriver? chrome undo the action of "prevent this page from creating additional dialogs"