我需要打印出第二個數組,它從第一個數組中獲取數字。如果第二個數組有重複項,它將只打印一次數字。我現在的代碼打印第一個數組的最後一個數字20次....我不能爲我的生活找出如何做到這一點。我討厭用簡單的家庭作業問題來到這裏,但導師沒有幫助。如果你能幫助我,請包括一些評論與你在做什麼,我想學習這個!創建一個包含20個數字的數組,只要它們不是重複的,使用最小的數組打印每個數值?
<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>
謝謝你,你的答案是非常有幫助! – Craig 2011-03-04 06:52:14