Trying to run a simple check on an Array of Strings to see if it contains any elements from another Array of Strings but running into some unexpected behavior. In the tests below, both arrays have the b
string.
However, the conditional statements do not seem to recognize it. Why is this happening?
const array1 = [ 'a', 'b', 'c', 'd' ] ;
const array2 = [ 'e' , 'f' , 'g' , 'b' ] ;
// test 1
array1.includes( ...array2 ) ?
console.log( 'error' ) :
console.log( 'no error' ) ;
// test 2
array1.includes( 'e' , 'f' , 'g' , 'b' ) ?
console.log( 'error' ) :
console.log( 'no error' ) ;
// test 3
if( array1.includes( 'e' , 'f' , 'g' , 'b' ) ) { console.log( 'error' ) }
else { console.log( 'no error' ) }