Used the recommended method of searching val in array.
Fixed type comparison to 'boolean'.