日期:2014-05-16 浏览次数:20343 次
var arr1=["aaa","b","cc"];
var arr2=["a","aaab","c","d"];
var arr3=["a","ab","asc","d","e"];
var aa = arr1.concat(arr2,arr3).sort().join(";");
bb = aa.replace(/([^\;]*)(\;\1)+(?:$
------解决方案--------------------
\;)/g,""); //去掉所有重复的,如果在数组多次出现,则去掉
cc = aa.replace(/([^\;]*)(\;\1)+(?:$
------解决方案--------------------
\;)/g,"$1;"); //去掉重复,如果多次出现,则去掉多余的,留唯一的一个。
console.log(bb);
console.log(cc);
var a = [ "a" , "b" , "c" ],
b = [ "b" , "c" , "d" ],
c = [ "c" , "d" , "e" ],
_a = a.concat( b ).concat( c ),
_hash = {},
_new = [];
for( var i = _a.length; i--; ){
if( !_hash[ _a[ i ] ] ){
_hash[ _a[ i ] ] = 1;
_new.push( _a[ i ] );
};
};
return _new;