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 8680343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:13:30+00:00 2026-06-12T21:13:30+00:00

Possible Duplicate: Remove duplicates from array Could you please help me out. I have

  • 0

Possible Duplicate:
Remove duplicates from array

Could you please help me out. I have this piece of code..

   <html>
  <head>
  <title>test</title>
  <script>

  var array = new Array();

  function insert(val){
  array[array.length]=val;
  }

  function show() {
  var string="";
  for(i = 0; i < array.length; i++) {
  string =string+array[i]+' , ';
  }
  if(array.length > 0)
 document.getElementById('result').innerHTML = string;
  }

  function removeDuplicateElement(arrayName)
            {
                var newArray=new Array();
                label:for(var i=0; i<arrayName.length;i++ )
                {   
                    for(var j=0; j<newArray.length;j++ )
                    {
                        if(newArray[j]==arrayName[i]) 
                        continue label;
                    }
                    newArray[newArray.length] = arrayName[i];
                }
                return newArray;
                document.getElementById('result1').innerHTML = newArray;
            }
  </script>

  </head>

  <body>
  <h2>Demo</h2>
  <form name="form1">
  <input id="userinput" type="text" name="Input"/>
  <input type="button" Value="Add" onclick="insert(getElementById('userinput').value),show();"/>
  <input type="button" Value="Substract" onclick="removeDuplicateElement(array);"/>
  </form>
   <textarea style="border:1px solid #B3B3B3; width:218px;" rows="2" cols="30" type="text"  id="result"></textarea>
   <textarea style="border:1px solid #B3B3B3; width:218px;" rows="2" cols="30" type="text"  id="result1"></textarea>
  </body>
</html>

And I was trying to implement the remove duplicate function I found on the internet without any success. (see below) What am I doing wrong?

function removeDuplicateElement(arrayName)
{
  var newArray=new Array();
  label:for(var i=0; i<arrayName.length;i++ )
  {  
      for(var j=0; j<newArray.length;j++ )
      {
          if(newArray[j]==arrayName[i]) 
          continue label;
      }
      newArray[newArray.length] = arrayName[i];
  }
  return newArray;
}

Thank you!

  • 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-06-12T21:13:32+00:00Added an answer on June 12, 2026 at 9:13 pm

    A few (hopefully) useful code tips:

    1. Don’t use new Array() unless you want to make an array that’s a fixed size (unusual). Use [] instead.
    2. arr.push(item) is the same thing as arr[arr.length] = item, except better.
    3. That loop in your show function can be accomplished using array.join(' , ').

    Anyway, the actual problem is here:

    return newArray;
                document.getElementById('result1').innerHTML = newArray;
    

    return exits the function. It looks like you want to take out the return part.

    … but anyway, that code is pretty wasteful. I would write it as:

    function removeDuplicateElements(array) {
        document.getElementById('result1').innerHTML =
            array.filter(function(item, index) {
                return array.indexOf(item) !== index;
            });
    }
    

    … assuming a modern browser that supports Array#indexOf and Array#filter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Remove duplicates from array I have a list of items. I want
Possible Duplicate: Remove duplicates from array I have an int array which contains a
Possible Duplicate: Java Remove Duplicates from an Array? String={3333,4444,5555,5555,1111} Using Delimiter i have put
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: How to remove elements from an array I have an List with
I have this code from this link: How can I remove duplicate rows? ;WITH
Possible Duplicate: More efficient way to remove elements from an array list I have
Possible Duplicate: Bus error troubleshooting To remove duplicates from a string this is the
Possible Duplicate: How do you remove duplicates from a list in Python whilst preserving
Possible Duplicate: remove duplicate from string in PHP Have a string like: $str =

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.