How to use Lodash _.strContains() Method In Javascript
In this example, we are using the Lodash _.strContains() method that return the boolean value true if the given value is present in the given string else it returns false.
Example: This example shows the implementation of the above-explained approach.
// Defining lodash contrib variable
let _ = require('lodash-contrib');
let bool = _.strContains("abc", "a");
console.log("The String contains the "
+ "searched String : ", bool);
Output:
The String contains the searched String : false
Check an array of strings contains a substring in JavaScript
Checking if an array of strings contains a substring in JavaScript involves iterating through each string in the array and examining if the substring exists within any of them. This process ensures efficient detection of the substring’s presence within the array.
These are the following ways to do this:
Table of Content
- Using includes() method and filter() method
- Using includes() method and some() method
- Using indexOf() method
- Using Lodash _.strContains() Method
- Using a for of loop