I have the following JS arrays.
$arrTest1 = ['46819', '46819', '46819'];
$arrTest2 = ['46819', '46802', '46819'];
let len1 = arrTest1.length;
let len2 = $.unique(arrTest1).length;
if (len1 > len2) {
alert('Found duplicate');
} else {
alert('Did not find duplicate');
}
let len3 = arrTest2.length;
let len4 = $.unique(arrTest2).length;
if (len3 > len4) {
alert('Found duplicate');
} else {
alert('Did not find duplicate');
}
For first array $arrTest1 its working and showing found duplicate but for $arrTest2 its showing as Did not find duplicate. Did I missed something?
$.unique is not working for $arrTest2 whereas for $arrTest1 it works fine.
3
Answers
Documentation:
You can use Set like my example
You can use
$.merge()
is used to combinearray1
andarray2
intocombinedArray
.$.grep()
is used to filtercombinedArray
and find the duplicate values, which are stored induplicateValues
.Refer below Code
$.unique
has be removed inV.3.0
and above you can do it using$.grep()