- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - includes method
Syntax
_.includes(collection, value, [fromIndex=0])
Checks if value is in collection. If collection is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons. If fromIndex is negative, it's used as the offset from the end of collection.
Arguments
collection (Array|Object|string) − The collection to inspect.
value (*) − The value to search for.
[fromIndex=0] (number) − The index to search from.
Output
(boolean) − Returns true if value is found, else false.
Example
var _ = require('lodash'); var list = [1 ,2, 3, 4]; var result = _.includes(list, 1); console.log(result); result = _.includes('one', 'ne'); console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
true true
lodash_collection.htm
Advertisements