Three kinds of JS to remove duplicate code

Source: Internet
Author: User

<script language= "Web Effects" >
<!--
var stra= "1,2,3,4,5,6,7";
var strb= "2,0,4,6,8,9";
Need to remove 2,4,6 three elements
var str=stra+ "," +STRB;
var strarr=str.split (",");
Sort
Strarr.sort ();
var result=new array ();
var temps tutorial tr= "";
for (var i in Strarr)
{
if (Strarr[i]!= tempstr)
{
Result.push (Strarr[i]);
Tempstr=strarr[i];
}
Else
{
Continue
}
}
Alert (Result.join (","))
-->
</script>

Here's what I've been searching for on the internet.

Delete the elements in the array with duplicate values, please enlighten me if you have any good suggestions.

Code:

function Removeduplelem ()
{
var array = new Array ();
for (var i=0; i<10; i++)
{
Array.push (i+ "name");
}
Array.push ("3name");
Array.push ("5name");
Array.push ("9name");
Array.push ("3name");

Array.push ("9name");
Array.push ("9name");

for (var i=0; i<array.length; i++)
{
for (var j=i+1; j<array.length;j++)
{
if (Array[i]==array[j])
{
Array = removeelement (J,array);//delete the element of the specified subscript (in the previous article)
i=0;
Break
}
}
}
for (var i=0; i<array.length; i++)
{
Alert (Array[i]);
}

return array;
}

Method Three

<script>
var shu=array ("110846896", "110846897", "110846896");
for (Var i=0;i < shu.length;i++)
{
for (var j=i+1;j<shu.length;j++)
{
   if (shu[i]==shu[j])
    {
     shu[i]=0;
     break;
  }
}
if (Shu [i]!=0)
{
   document.write (shu[i] + "<br>");
}
}
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.