---
title: "How to search for a substring in a string in Javascript?"  
description: "How to search for a substring in a string in Javascript?"  
author: "Anoop Singh"  
published: 2011-02-28  
updated: 2011-02-28  
canonical: https://www.mindstick.com/forum/174/how-to-search-for-a-substring-in-a-string-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# How to search for a substring in a string in Javascript?

Hi,\
\
I'm new to [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) and have [requirement](https://yourviews.mindstick.com/view/85169/becoming-an-influencer-requirement-of-skills-and-knowledge) where I have to [check whether](https://www.mindstick.com/forum/157543/write-a-java-program-to-check-whether-a-string-is-a-palindrome) particular [sub string](https://www.mindstick.com/forum/34401/get-sub-string-from-a-string-in-mvc) exist in a string or not.\
\
Thanks in advance.

## Replies

### Reply by Anonymous User

Hi Anoop,\
\
You can search sub [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) in a string using search() method of Javascript\
\
Here is the example,\

```
var mainString = 'Hello world'; if (mainString.search('world') >= 0)        alert('Exist');
```

Hop this will solve your problem.


---

Original Source: https://www.mindstick.com/forum/174/how-to-search-for-a-substring-in-a-string-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
