Elias Sjögreen Elias Sjögreen - 1 year ago 187
Node.js Question

Check if string contains word at start of string

I am starting to learn a little bit more advanced js and i want to check if string contains a word at the start of the line.
Something like this would be good!:

var string = "Hello world";
if (string.contains("Hello", start) == true)

Answer Source

Very easy Method:

var str = "Hello World";

if (str.startsWith("Hello")){
    do stuff;

You could also make two arrays and compare the single letters using a for loop, slightly more creative :D

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download