JavaScript has rich library of functions to work with array and string. Sometimes working in Javascript, you might need to verify if a string contains specific substring or not.
This is same method as we use %Like%
query with SQL. There are two ways, you can check if string contains substring.
String.prototype.includes()
returns true if string contains any substring or not. For example,
var mainString = "laravelcode.com";
var subString = "stuff";
console.log(mainString.includes(subString)); // true
String.prototype.includes was introduced in ECMAScript 6, which not support to Internet Explorer or older browsers.
String.prototype.indexOf
supports ECMAScript 5 or older, so it will return -1 if string not contains substring. For example,
var mainString = "laravelcode.com";
var subString = "stuff";
console.log(mainString.indexOf(subString) !== -1); // true
I hope you liked this article and it will help a little on your project.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Google Line Chart with Example in VueJs
Today,I will learn you how to create Goo...How to Create CSV file in Python 3
In this article, I will share with you h...Laravel 8 - jQuery Ajax File Upload with Progress Bar Tutorial
In this article, i will share with you h...Send Verification Mail to New User in Anguler9
Hello folks, In this Angular 7/8/9 Fireb...Failed to listen on 127.0.0.1:8000 (reason: Address already in use)
Laravel is the most popular and open-sou...