I want to create a dynamic array with data from the input. Later I want to write the collected data to the in div. How can I do that?
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<body>
<p>Click the button to add a new element to the array.</p>
<input type="text" id="data">
<button onclick="myFunction()">Try it</button>
<button onclick="myFunction2()">Add</button>
<p id="demo"></p>
<script>
var fruits = [];
function myFunction() {
var x=$("#data").val();
fruits.push(x);
$("#data").val("");
for(var i=0;i<fruits.length;i++) {
$("#demo").html(fruits[i]);
}
}
</script>
</body>
</html>