Thursday, July 26, 2018

Compare two arrays and return duplicate values

var x = ['IdA', 'idB', 'IdC', 'IdD', 'IdE'];
var y = ['idB', 'IdE', 'IdF'];

var z = x.filter(function(val) {
  return y.indexOf(val) != -1;
});

o/p : ["idB", "IdE"]

No comments:

Post a Comment

function declaration, expression and call/invoke/execution

  The  function  declaration defines a function with the specified parameters. The  function   keyword can be used to define a function ins...