Check whether a string starts with another string in using JavaScript

Is there a function or a workaround to check whether a string starts with another string in JavaScript?

Ex. to check "pr" from "programmersheaven".

Comments

  • var data   = "programmersheaven";
    var search = "pr";
    
    var result = (data.indexOf(search) == 0);
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion