back to Overview

.contains()

Checks whether the list contains the given item.
Util module only.

Syntax Variants

list.contains(item)
_.contains(list, item)

Parameters

list
A list to check. Can be an array, a Minified list or any other array-like structure with length property.
item
The item to search.
(return value)
true if the list contains the item. False otherwise.

Description

Checks whether the list contains the given item.

Each item of the other list is compared with the item using _.equals(). The function returns true as soon as one list item equals the requested item.

Example

Checks whether a list contains a 5:

var r = _(1, 2, 3, 4, 5).contains(5);   // returns true

Example

The same using an array:

var r = _.contains([1, 2, 3, 4, 5], 5); // returns true

See also..

  • find() finds the position of a list element's fist occurrence.
  • findLast() finds the last position of a list element.

Comments

comments powered by Disqus

back to Overview

Functions