Dieser Artikel beschreibt die Implementierungsmethode von JS Clearing -doppelten Werten in Zeichenfolgen. Teilen Sie es für Ihre Referenz wie folgt weiter:
/// <summary> /// Duplikatwerte in der String /// </summary> /// <param name = "text"> string </param> /// <param name = "label"> label (wie: |,) </param> Funktion filterrepeatstr (text) {var sarr = text.split ('' + + '); var idx = new Array (); var tmp = new Array (); var result = cm = ''; für (var i = 0; i <sarr.length; i ++) {sch = sarr [i] .substr (0, 4); if (! in_array (sch, tmp)) {idx [idx.length] = i; tmp [tmp.length] = Sch; } else {idx [in_array (sch, tmp) - 1] = i; }} für (var j = 0; j <idx.length; j ++) {result += cm +sarr [idx [j]]; cm = '' + label + ''; } Rückgabeergebnis; // alert ('Katalog String:' + text); // alert ('Ergebnis:' + result);} Funktion in_array (nötig, arr) {für (var i = 0; i <arr.length; i ++) {if (arr [i] == Bedarf) return (i + 1); } return false;}PS: Hier empfehle ich ein Online -Tool mit der gleichen Funktion als Referenz:
Online -Entfernungstool:
http://tools.vevb.com/code/quchong
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript traversal algorithms and techniques", "Summary of json operation techniques in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript -Animationseffekte und -techniken "," Zusammenfassung der JavaScript -Fehler und Debugging -Techniken "und" Zusammenfassung der Nutzung von JavaScript -Mathematikoperationen ""
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.