I am trying to check duplicate in the following array, just i am want to return true or false if duplicate exists.
var array = ["Saturday", "Sunday", "Monday", "Tuesday", "Saturday" ];
for ( var i = 0; i < array.length; i++){
for (var j = i+1; j< array.length; j++){
if (array [i] === array [j]){
console.log(array[i]);
}
}
}
I tried the above , it giving result only for one item in an array not for comma separated. How i can write a duplicate check function in best way for comma separated array?
Array(10)
0: "test3,tier 1,test,test2
"1: "test3,tier 1,test,test2
"2: "test3,tier 1,test,test2
"3: "test3,tier 1,test,test2
"4: "test3,tier 1,test,test2
"5: "test3,tier 1,test,test2
"6: "test3,tier 1,test,test2
"7: "test3,tier 1,test,test2
"8: "test3,tier 1,test,test2
"9: "test3,tier 1,test,test2
"length: 10
__proto__: Array(0)
console.log... return false outside of the loopsnew Set(array).size === array.lengthis true if all array items are uniquea.map(item=> item .split(',').map(child => child)).map(item => new Set(item).size === item.length)try by doing this may be this solves your problem