Get the last value after spliting a string with hyphen in jquery? -


hi have string separated hyphens in , want lastindex of string , replace new value

   var str1="new-new_folder"; //replace new_folder folder str becomes    var newstr1="new-folder";      var str2="new-new_folder-new_folder"; //replace last new_folder sub_folder str becomes    var newstr2="new-new_folder-sub_folder"; 

can 1 me here?

you can use split last index length minus one:

var string = "some-hyphen-string"; var parts = string.split("-"); var lastpart = parts[parts.length - 1]; //lastpart final index string split 

demo: http://jsfiddle.net/acfru/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -