How do I check if a string contains a specific substring in JavaScript

0 votes
With the help of code can you tell me How do I check if a string contains a specific substring in JavaScript?
Feb 12 in Java-Script by Nidhi
• 11,580 points
64 views

1 answer to this question.

0 votes

You can use the includes() method, introduced in ECMAScript 6 (ES6).

Using includes():

This method returns true if the substring is found within the string and false otherwise.

const mainString = 'Hello, Edureka!';

const subi = 'Edureka';

console.log(mainString.includes(subi)); // Output: true

In this example, mainString.includes(subi) evaluates to true because 'Edureka' is a substring of 'Hello, Edureka!'. It's important to note that includes() is case-sensitive.

answered Feb 12 by Kavya

Related Questions In Java-Script

0 votes
0 answers

How do I check if an array includes a value in JavaScript?

What is the quickest and most effective method to determine whether a JavaScript array has a value? The only method I am aware of is as follows: function contains(a, obj) { ...READ MORE

Sep 23, 2022 in Java-Script by Abhinaya
• 1,160 points
854 views
0 votes
1 answer
0 votes
1 answer

How do I break a string across more than one line of code in JavaScript?

Hello @kartik, In your example, you can break ...READ MORE

answered Oct 8, 2020 in Java-Script by Niroj
• 82,840 points
775 views
0 votes
1 answer

How to run an HTML file using Node.js?

1.Install Node.js 2.Create a Project Folder mkdir html-node-app cd html-node-app 3.Initialize ...READ MORE

answered Feb 12 in Node-js by Navya
57 views
0 votes
1 answer

How can I dynamically validate Angular forms based on user input?

Dynamic Form Controls with Validation: In scenarios where ...READ MORE

answered Feb 12 in Angular by Navya
67 views
0 votes
1 answer
0 votes
0 answers

How can I determine if a string begins with another string?

With the help of code snippets, can ...READ MORE

Jan 9 in Java-Script by Ashutosh
• 20,870 points
81 views
0 votes
1 answer

How can I properly format a date in JavaScript?

You can format a date in JavaScript ...READ MORE

answered Jan 10 in Java-Script by anonymous
112 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP