27th December 2007 - 5 minutes read time
Here are a few of the built in JavaScript functions available.
To get the length of a string use the length variable. This returns the number of characters in a string.
var str = 'abcdef';
str.length; // returns 6
The charAt function will return the character at the point specified in the parameter. So to get the first character of a string use:
var str = 'abcdef';
str.charAt(0); // returns a
To get the last character of a string use a combination of charAt and length.
var str = 'abcdef';
str.charAt(str.length - 1); // returns 'f'
To get the position of a character or group of characters in a string use the indexOf function. The function returns -1 if the string is not found.