close

How can I check that a string does not include the text of another string?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I check that a string does not include the text of another string? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How can I check that a string does not include the text of another string ?

  1. How can I check that a string does not include the text of another string ?

    can I check that a string does not include the text of another string var include_flag = toState.name.includes("home.subjects.subject.exams.exam.tests"); return !include_flag;
    Using the JS includes method would probably be your best bet. I get I'm a little late in answering this question, but I was just googling this myself and came up with this answer after some fiddling with the code. This code will return true

  2. How can I check that a string does not include the text of another string ?

    can I check that a string does not include the text of another string var include_flag = toState.name.includes("home.subjects.subject.exams.exam.tests"); return !include_flag;
    Using the JS includes method would probably be your best bet. I get I'm a little late in answering this question, but I was just googling this myself and came up with this answer after some fiddling with the code. This code will return true

Method 1


ES6 version of this is (check out answer from Allison):

!str1.includes(str2)

The original accepted answer was:

You are looking for indexOf

var x = "home.subjects.subject.exams.exam.tests";
console.log(x.indexOf('subjects'));     // Prints 5
console.log(x.indexOf('state'));        // Prints -1

Method 2

var include_flag = toState.name.includes("home.subjects.subject.exams.exam.tests");
return !include_flag;

Using the JS includes method would probably be your best bet. I get I’m a little late in answering this question, but I was just googling this myself and came up with this answer after some fiddling with the code. This code will return true if toState.name does NOT include the string given.

Hope this helps anyone searching the same question I had!

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment