How to find Right of string in Lightning Component Controller?

How to find Right of string in Lightning Component Controller?

Sample Code:


Lightning Component:


  1. <aura:component implements = “force:appHostable”>    
  2.       
  3.     <aura:attribute name = “str” type = “String”/>  
  4.       
  5.     <aura:handler name = “init” value = “{!this}” action = “{!c.onInit}”/>  
  6.       
  7.     <div class = “slds-box slds-theme_default”>   
  8.       
  9.         String is {! v.str }  
  10.           
  11.     </div>  
  12.         
  13. </aura:component>  



Lightning Controller:


  1. ({    
  2.       
  3.     onInit : function( component, event, helper ) {    
  4.           
  5.         var temp = ‘testing’;  
  6.         var tmp = temp.substr( -2 );  
  7.         component.set( “v.str”, tmp );  
  8.           
  9.     }  
  10.       
  11. })  



Output:


Leave a Reply