This article describes the implementation method of JS clearing duplicate values in strings. Share it for your reference, as follows:
/// <summary>/// Clear duplicate values in the string /// </summary>/// <param name="Text">String</param>/// <param name="Label">Label (such as: | ,)</param>function FilterRepeatStr(Text, Label) { var sarr = Text.split('' + Label + ''); var idx = new Array(); var tmp = new Array(); var result = cm = ''; for (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; } } for (var j = 0; j < idx.length; j++) { result += cm + sarr[idx[j]]; cm = '' + Label + ''; } return result;// alert('Catalogue string: ' + Text);// alert('Result: ' + result);}function In_Array(need, arr) { for (var i = 0; i < arr.length; i++) { if (arr[i] == need) return (i + 1); } return false;}PS: Here I recommend an online tool with the same function for your reference:
Online Removal Tool:
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 animation effects and techniques", "Summary of JavaScript errors and debugging techniques" and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.