Compare values in two arrays using Iterator in Javascript? -


i know how compare values in 2 arrays using 2 loops looking bit more sophisticated creating iterator iterate through 1 of arrays , passing other array mapmethod . possible?

i'm doing small program class takes array , x arguments , have extracted values arguments.

function dest(arr){   var args =[];   for(var = 1; < arguments.length; i++){     args.push(arguments[i]);   }    return args; }  console.log(dest([1, 2, 3, 4], 4, 4)); 

now, how iterator part compare values inside arr , args? help.

the result should results match both arr , args.

you can use built in filter method

var arr = [2, 3, 4, 5, 6]; var args = [3, 5, 6, 7];  var result = arr.filter(function(element) {     return args.indexof(element) > -1; }); 

this filter out elements out not present in both arrays. result new array contains matching values [3, 5, 6].


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -