Peter Michaux petermichaux at
Thu Feb 23 18:18:21 PST 2012

On Thu, Feb 23, 2012 at 12:35 PM, Mark S. Miller <erights at> wrote:

>     if (arr.contains(foo)) {
> vs
>     if (arr.indexOf(foo) !== -1) {

The readability of the above two options is very different. The first
option is far superior as it expresses what the programmer wants to
know. The second options is an expression of how it can be
accomplished and requires understanding of indexOf's return values.

I think the addition Array.prototype.contains would be a good, simple
one that would improve programs. The fact that this function exists in
libraries means it is useful in a general in the opinion of at least
several programmers.


More information about the es-discuss mailing list