<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
How to Find the XOR of Values
of an Array in JavaScript?
</
title
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksForGeeks
</
h1
>
<
h3
>
How to Find the XOR of Values
of an Array in JavaScript?
</
h3
>
<
h4
>
----Given Array----<
br
>
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</
h4
>
<
button
onclick
=
"myGeeks()"
>Click</
button
>
<
p
id
=
"gfg"
></
p
>
<
script
>
function XOR(input)
{
if (toString.call(input) !== "[object Array]")
return false;
var total = Number(input[0]);
for(var i=1;i<
input.length
;i++) {
if(isNaN(input[i])){
continue;
}
total ^= Number(input[i]);
}
return total;
}
function myGeeks(item) {
document.getElementById("gfg")
.innerHTML
=
"----XOR of Array----"
+ "<br>"
+ XOR([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
}
</
script
>
</
body
>
</
html
>