RSS

String operations in javascript

11 Apr

Find last two character in string:

var chrStr = "find last two character";
var last2 = chrStr.slice(-2);
(OR)
var last2 = chrStr.substr(chrStr.length-2);
alert(last2); // "er"

Remove last 2 character in string:

var str = "remove last two character";
str = str.substring(0, str.length - 2);
alert(Str); // remove last two charact
 
Leave a comment

Posted by on April 11, 2013 in Javascript

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: