例如:
var didd = [ '11', '22', '33', '44', '22', '33', '22', '33', '22', '33' ];
methods:{
findSame( arr ) {
arr.sort();
var comm = [];
var commTwo = [];
for ( var i = 0; i < arr.length - 1; i++ ) {
if ( arr[ i ] == arr[ i + 1 ] ) {
//alert( "包含相同元素,相同值为:" + arr[ i ]);
comm.push( arr[ i ] );
if ( arr[ i + 1 ] != arr[ i + 2 ] ) {
comm.push( arr[ i + 1 ] );
commTwo.push( comm );
comm = [];
}
} else {
if ( i == 0 ) {
comm.push( arr[ i ] );
commTwo.push( comm );
comm = [];
}
if ( i > 0 ) {
alert( i );
var aa = arr[ i ];
var bb = arr[ i - 1 ];
console.log( aa );
if ( aa != bb ) {
comm.push( aa );
commTwo.push( comm );
comm = [];
console.log( '44' );
}
}
}
};
var ccc = arr.length - 1;
comm.push( arr[ ccc ] );
commTwo.push( comm );
comm = [];
return commTwo;
},
},
调用时直接var ss =findSame( didd ); 得到的即为筛选后的数组