Home > Web Front-end > JS Tutorial > Specific implementation of obtaining non-duplicate values ​​​​in 3 arrays_javascript skills

Specific implementation of obtaining non-duplicate values ​​​​in 3 arrays_javascript skills

WBOY
Release: 2016-05-16 17:06:06
Original
1134 people have browsed it
Copy code The code is as follows:

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;

Idea: First use concat to splice arrays, and then use an object and a new array (used to store non-duplicate arrays).

Traverse the old array and put the values ​​into the object. If the values ​​are different, they will be put into the new array. If they are repeated, they will not be placed.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template