I have three strings which contain comma separated numbers.
var str1 = "1,5,3";
var str2 = "2,5,1";
var str3 = "3,2,1,5";
I want to check these three strings with each other (To get the common elements between all)
Expected output
var result = 1,5;
If I have only two strings, this is the logic I have already used
var array = str2.split(',');
for(var item in array) {
var contains = (str1.indexOf(array[item]) > -1);
if(contains == 1) {
var result = array[item]+',';
getele2 += result;
geteleresult = getele2.replace(/\,$/, '');
}
}
alert(geteleresult);
but when multiple strings are checked i dont know how to apply sort logic for these. Any idea then please help thanks...