How to check if a string “StartsWith” another string?

后端 未结 19 1331
我在风中等你
我在风中等你 2020-11-21 22:35

How would I write the equivalent of C#\'s String.StartsWith in JavaScript?

var haystack = \'hello world\';
var needle = \'he\';

haystack.startsWith(needle)          


        
19条回答
  •  终归单人心
    2020-11-21 23:02

    I am not sure for javascript but in typescript i did something like

    var str = "something";
    (str).startsWith("some");
    

    I guess it should work on js too. I hope it helps!

提交回复
热议问题