I need to print out a second array, that takes the numbers from the first array. The second array will only print the number once if it has a duplicate. The code I have now prints the last number of the first array 20 times…. I can’t for the life of me figure out how to do this. I hate coming here with simple homework questions but the tutor is no help. If you can help me, please include some comments with what your doing, I want to learn this!
<html>
<head>
<title> HW 10.12 </title>
<script type="text/javascript">
var array=new Array(19);
var array2 =new Array();
for(var j=0; j< array.length; j++)
{
array[j]=Math.floor(10 + Math.random()*100);
}
for (var i=0; i < array.length; i++)
for(var k=0; k < array.length; k++)
{
if (array2[k] != array[i])
{
array2[k] = array[i];
}}
document.writeln(array2)
</script>
</head>
<body>
</body>
</html>
Change your javascript to as follows: