Alex Rivera | Logout

Find substring with Jquery?

Asked 2010-05-18T04:13:54.790
19

How would our group find out if a particular string contains a certain substring? Only with the help of , please.

Edit
Report

1 Answer

38

You don't really need jQuery for such a simple thing, you can simply use the indexOf method of String objects, e.g.:

var str = "foobar";
var containsFoo = str.indexOf('foo') >= 0; // true

The indexOf method returns the character index where the first occurrence of the specified value is encountered, if not found, it returns -1.

answered 2010-05-18T04:16:22.177

Your Answer