Skip to main content Accessibility Feedback

Strings

String.indexOf()

Determine if a string contains a substring. It returns the index of where the substring starts in the string, or -1 if the substring isn’t found. It’s case-sensitive.

var str = 'I love Cape Cod potato chips.';

// Returns 7
str.indexOf('Cape Cod');

// Returns -1
str.indexOf('cape cod');

Works back to at least IE6.