About Maik Vlcek Follow me on twitter
Themenschwerpunkte dieses Blogs:

Javascript: Duplikate entfernen / remove duplicates

Javascript
Share and Enjoy: Diese Icons verlinken auf Bookmark Dienste bei denen Nutzer neue Inhalte finden und mit anderen teilen können.
  • MisterWong
  • Digg

Dieses Script entfernt Duplikate sowohl aus Strings, als auch aus Arrays.

Sie ist einfach und schnell.
Getestet unter IE6/7, Firefox 2, Opera 9.02, Netscape 7

function removeDuplicates(hasDup){

	var noDup = new hasDup.constructor;

	if(noDup.push){
		noDup[0] = hasDup[0];

		for(i=1;i<hasDup.length;i++){
			for(j=0;j<noDup.length;j++)
				if(hasDup[i] == noDup[j])
					break;
			if(j<noDup.length) continue;

			noDup.push(hasDup[i]);
		}
	}
	else{
		noDup = hasDup.charAt(0);

		for(i=1;i<hasDup.length;i++){
			for(j=0;j<noDup.length;j++)
				if(hasDup.charAt(i) == noDup.charAt(j))
					break;
			if(j<noDup.length) continue;

			noDup = noDup.concat(hasDup.charAt(i));
		}
	}

	return noDup;
}

Download

removeDuplicates in Javascript [*.js-File]

Publiziert am 08. Jun. 2007 von mediavrog in , , . Kategorie: JS.

Share and Enjoy: Diese Icons verlinken auf Bookmark Dienste bei denen Nutzer neue Inhalte finden und mit anderen teilen können.
  • Y!GG
  • MisterWong
  • Linkarena
  • Facebook
  • TwitThis
  • email
  • del.icio.us
  • Digg
  • StumbleUpon
  • Technorati
Monster-Me eating knowledge
2 Kommentare RSS Icon
Trackback URL
Einen Kommentar hinterlassen

Du kannst die folgenden Tags verwenden: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  1. mediavrog

    Quelle: mediavrog auf mediavrog.net

  2. Eric

    Was hältst du davon die Quelle zu posten?

top top