Manipulating Strings

The String object is by far the most commonly used object in JavaScript. JavaScript automatically creates a String object for you any time you define a variable that has a string data type. For example:

var myStr = "Teach Yourself jQuery & JavaScript in 24 Hours";

When you create a string, there are a few special characters that you can’t add directly to the string. For those characters, JavaScript provides a set of escape codes, listed in Table 2.5.

Image

Table 2.5 String object escape codes

To determine the length of a string, you can use the length property of the String object, as in this example:

var numOfChars = myStr.length;

The String object has several functions that allow you to access and manipulate the string in various ways. The methods for string manipulation are described in Table 2.6.

Image

Table 2.6 Methods to manipulate String objects

To get you started on using the functionality provided in the String object, the following sections describe some of the common tasks that can be done using String object methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.44.94