JavaScript lastIndexOf()

javascript, jquery

Solution

You were close -- just case sensitive:

ID = ID.substring(ID.lastIndexOf("_") + 1);

JS Fiddle Example

Problem

In C# I can do this ``` string ID = "ContentPlaceHolderDefault_MainSiteSectionArea_MyPagePlaceHolder_Item4_FavoritAmusementCalender_6_deleteRight_2";    ID = ID.Substring(ID.LastIndexOf("_") + 1);  ``` to return the last int `2` How can I most easily do this in jQuery/JavaScript The id is created dynamic and can for now be up to 3 digit. Thanks in advance.

Original source