Find XOR of all elements in an Array | Function to find the XOR of all elements in the array ; Resultant variable ; Iterating through every element in the array ; Find XOR with the result ; Return the XOR ; Driver Code ; Function call
function xorOfArray ( arr , n ) { let xor_arr = 0 ; for ( let i = 0 ; i < n ; i ++ ) { xor_arr = xor_arr ^ arr [ i ] ; } return xor_arr ; } let arr = [ 3 , 9 , 12 , 13 , 15 ] ; let n = arr . length ; document . write ( xorOfArray ( arr , n ) + " " ) ;