jquery removes array repeating elements

Source: Internet
Author: User

There's a problem to be aware of.
Arr[j]==i you seem to refer to the equality judgment when an array element is a number type ...
But often we may have to make equality judgments about different types of ... This is the practical application of the problem should be considered

Case of 1!=new number (1)
The situation of null==undefined

0== "0" situation and so on

So obviously simple = = and = = are not suitable.
A Equals method should be implemented independently to make equality judgments ... To set rules based on requirements


var x=[1,1,3,4,5,3];
var y=[];
var tarray=function (I,arr) {
var Yap=false;
for (Var j=0;j<arr.length;j++) {
if (arr[j]==i) {yap=true;break;};
}
if (!yap) Arr.push (i);
};
for (Var t=0;t<x.length;t++) {
Tarray (X[t],y);
}
alert (y.length);
Alert (y.tostring ());

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.