How would I write the equivalent of C#\'s String.StartsWith in JavaScript?
var haystack = \'hello world\'; var needle = \'he\'; haystack.startsWith(needle)
Also check out underscore.string.js. It comes with a bunch of useful string testing and manipulation methods, including a startsWith method. From the docs:
startsWith
startsWith _.startsWith(string, starts) This method checks whether string starts with starts. _("image.gif").startsWith("image") => true
startsWith _.startsWith(string, starts)
_.startsWith(string, starts)
This method checks whether string starts with starts.
string
starts
_("image.gif").startsWith("image") => true