_.contains method is used to check an element in array exists or not in Underscore.js.
Prototype : _.contains(list, value, [fromIndex])
It will take three arguments first two are required and third is optional. The internally _.contains method uses indexOf if the supposed list is a type of array.
var arrayList=['aaa', 'bbb', 'cfp', 'ddd']; var needle1="cfp"; var needle2="abc"; _.contains(arrayList, needle1); // outputs true _.contains(arrayList, needle2); // outputs false
Collection Functions are functions that work on arrays, objects, and array-like objects such as arguments, NodeList and similar.Below is the list of some collection functions in Underscore.js.
Function name Prototype each : _.each(list, iteratee, [context]) map : _.map(list, iteratee, [context]) find : _.find(list, predicate, [context]) filter : _.filter(list, predicate, [context]) reject : _.reject(list, predicate, [context])
Readmore from http://underscorejs.org/#collections
Never Miss an Articles from us.