programming-examples/js/Array/Write a JavaScript program to add items in an blank array and display the items..js

21 lines
504 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
var x = 0;
var array = Array();
function add_element_to_array()
{
array[x] = document.getElementById("text1").value;
alert("Element: " + array[x] + " Added at index " + x);
x++;
document.getElementById("text1").value = "";
}
function display_array()
{
var e = "<hr/>";
for (var y=0; y<array.length; y++)
{
e += "Element " + y + " = " + array[y] + "<br/>";
}
document.getElementById("Result").innerHTML = e;
}