Compare part of string in JavaScript

javascript, string

Solution

You can use `indexOf`:

if ( stringB.indexOf( stringA ) > -1 ) {
  // String B contains String A
} 

Problem

How do I compare a part of a string - for example if I want to compare if string A is part of string B. I would like to find out this: When `string A = "abcd"` and `string B = "abcdef"` it needs to return true. How do I do that in JavaScript? If I use `substring(start, end)` I do not know what values to pass to the `start` and `end` parameters. Any ideas?

Original source