Javascript function to check if array contains a value