var theString = 'Angus Macgyver!'; var theStringMinusOne = theString.substring(0, theString.length-1); alert(theStringMinusOne);
That should pop up “Angus Macgyver”, without the exclamation point.
The slice function works similarly.
var theString = 'Angus Macgyver!'; var theStringMinusOne = theString.slice(0, -1); alert(theStringMinusOne);
I personally like the first option as substring is a familiar function across various languages. Honestly, there’s no difference though – pick your pleasure.