Posted On: Feb 22, 2018
_.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.
Example
var arrayList=['aaa', 'bbb', 'cfp', 'ddd']; var needle1="cfp"; var needle2="abc"; _.contains(arrayList, needle1); // outputs true _.contains(arrayList, needle2); // outputs false
Never Miss an Articles from us.
Underscore.js is a javascript library that provides helper functions to manipulate an object without extending code any ..
Collection Functions are functions that work on arrays, objects, and array-like objects such as arguments, NodeList and..