Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:27:49+00:00 2026-05-20T10:27:49+00:00

I need to print out a second array, that takes the numbers from the

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:27:50+00:00Added an answer on May 20, 2026 at 10:27 am

    Change your javascript to as follows:

    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);
    }
    
    var isDuplicate = false;    
    for (var i = 0; i < array.length; i++) {
        isDuplicate = false;
        for (var k = 0; k < array.length; k++) {
            if (array2[k] == array[i]) { //Check if this current value of array1 exists in array2
             //If yes then we should ignore this value
             // hence mark isDuplicate as true.
              isDuplicate = true; 
              break; //Break from loop as we don't need to check any further
            }
    
        }
        if(!isDuplicate ) //if isDuplicate is not true this value is unique. Push it to array2
           array2.push(array[i]); 
    }
    
    document.writeln(array2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to print out receipts that inserted into my database, and the latest
i need to print out numbers 1-100 in a random order. the print statement
I need to print report page that has couple of background images on it.
For my project, I need to make a program that takes 10 numbers as
I need to print real datbase type name from DbParameter.DbType , but when I
I need to print a two-dimensional array etc: var myArray = [ [0,1,2,0], [0,1,2,0]
I need to print a receipt from my web based apps using dot matrix
C++ So i need a way to get say the number 7 from the
I have a college assignment where I need to print out items sold by
The following code, prints out Derived Base Base But I need every Derived object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.