Here is a javascript function i dont understand
<script>
function CheckDuplicates()
{
var values = new Array()
values[0] = document.form1.test.options[document.form1.test.selectedIndex].value
values[1] = document.form1.test2.options[document.form1.test2.selectedIndex].value
values[2] = document.form1.test3.options[document.form1.test3.selectedIndex].value
for (var i=0; i<values.length;i++)
if (values.join(“~”).indexOf(values[i]) != values.join(“~”).lastIndexOf(values[i]))
{alert(“duplicate found”);return;}
}
</script>
I am stuck exactly here
if (values.join(“~”).indexOf(values[i]) != values.join(“~”).lastIndexOf(values[i]))
How it works ?
let me understand in step by step.
(1)
i see , values.join(“~”) =====> whats does it do ? i see a special char “~” ..whats the role of that ?
(2) values[i]) != values.join(“~”).lastIndexOf(values[i])====>what the heck going on here ? this is very much complex lookin….plz explain this part.
someone please explain in a simpler way.
thanks