How would I write the equivalent of C#\'s String.StartsWith in JavaScript?
var haystack = \'hello world\';
var needle = \'he\';
haystack.startsWith(needle)
Without a helper function, just using regex's .test method:
/^He/.test('Hello world')
To do this with a dynamic string rather than a hardcoded one (assuming that the string will not contain any regexp control characters):
new RegExp('^' + needle).test(haystack)
You should check out Is there a RegExp.escape function in Javascript? if the possibility exists that regexp control characters appear in the string.