Get last section of string - Javascript jQuery

Javascript examples for jQuery:String

Description

Get last section of string

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//  w w  w. ja  v  a 2  s  .  c  om
$('input').each(
    function(){
        var string = this.name;
        $(this).val(string.substring(string.lastIndexOf('[') + 1,string.length - 1));
    });
    });

      </script> 
 </head> 
 <body> 
  <input id="inputElem" name="somestring[subkey][subkey2]">  
 </body>
</html>

Related Tutorials