Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js
return list.indexOf(x) !== -1;

Array.prototype.includes() is preferred but if you are supporting browsers that are 5+ years old, for example IE11, and you are not using a transpiler, then the old syntax with indexOf is generally well-understood.
return list.includes(x);

ES7 (Works on strings from ES6)
with Ada.Containers.Vectors;
Result := List.Contains (X);

New implementation...