I've tried to compare the values using for loop and after comparing the value of textbox with array elements it has to print exist or not exists if it is exist it has to show alert message and the value can't be added to the array if it is unique then the value has to be added to the Array
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<input type="text" id="text1"></input>
<input type="button" id="button1" value="Add Email" onclick="add_element_to_array();"> </input>
<p id="Result"></p>
<p id="r"></p>
<script>
var x = 0;
var array = Array();
function add_element_to_array()
{
function checkValue(value,array){
var status = 'Not exist';
for(var i=0; i<array.length; i++){
var name = array[i];
if(name == value){
status = 'Exist';
}
document.getElementById("r").value = "status";
}
}
array[x] = document.getElementById("text1").value;
alert("Element: " + array[x] + " Added at index " + x);
x++;
document.getElementById("text1").value = "";
var e = "<hr/>";
for (var y=0; y<array.length; y++)
{
}
document.getElementById("Result").innerHTML = e;
}
</script>
</body>
</html>