Murali P

Murali P

  • 1.5k
  • 190
  • 16.5k

Filter method doubts

Oct 18 2023 7:46 AM

hi..
 first of all thanks to each person of this group for their help . 
as per my requirement having two arrays like below:

 test1 ={11,33}
 test2 ={//,"",**,33,44}
here the array lengths will not be same and all special characters are allowed.
here need to inform the user if any simpler value is there. Here in this example 33 is common.
used 2 loops to find. Still searching any smart way to do
tried the below way also but its looping twice it seems:
 $.isDuplicate = function (test1, tes2) {
            return $.grep(test1, function (I) {
                return $.inArray(I, test2) > -1;
            });
        };
        let result = $.isDuplicate (test1, test2).length > 0;
        return result;

kindly let me know ur exp on using the below one. Let me know if you have faced any issues of using the below code.

observed its working irrespective of the arrays length:

var result = test1.filter((obj) => test2.indexOf(obj) !== -1);
            if (result.length > 0) {
                return true;
            }

 


Answers (1)