Javascript String Object

Javascript String Object

String object is an object that contains some methods and properties to manipulate the string data type. String object has only one property that is length property to obtain the long of data string variable. The syntax of this property are as follows:

x = string_variable_name.length;
x = ('any text'). length;

The method of string objects allows us to obtain a piece / part of a string of data and also modify it.
Here is a table a few standard methods of string objects:

string.big () increase the font size one point
string.small () decrease the font size one point
string.blink () to transform text into a blink text
string.bold () to transform letters in text to bold text (tag <b>)
string.charAt (position) returns the character position to the position parameters
string.charCodeAt (position) returns the Unicode code position to the position parameters
concat (text1, text2, ...) to connect the text inserted text as a parameter from end to end
string.fontcolor (color) modify the color of the text (color parameters, can be text or hexadecimal)
string.fontsize (size) to modify the size of the text (size parameter in the form of an integer)
string.indexOf (substring, position) returns the position of the substring (letters or a collection of letters from a string), by searching from left to right, starting from the location of positional parameters.
string.lastIndexOf (substring, position) the same function but the method indexOf search from right to left direction
string.italics () to transform the letters in the text into italic (tag <i>) (URL) to transform text into hypertext (tags <a href>)
string.strike () transforms the text to lower case letters in strikethrough text (tag <strike>) string.sub () transform the text to subscript letters in the text (tag <sub>)
string.sup () transform the text to superscript letters in the text (tag <sup>)
string.substr (position, length) returns the substring (a few letters or words) that starts from the position parameter to how many units and along the length parameter
string.substring (position 1, position2) return substring (a few letters or words) which is located between position1 parameters and position2 parameter
string.toLowerCase () to transform all the letters in the text to lowercase
string.toUpperCase () to transform all the letters in the text to uppercase

Here is a miraculous example of using methods of string objects:

var test = 'computer science';

  • var result = charAt (test, 4); / / result is 'p'
  • var result = ("computer science"). CharAt (6); / / result is 't'
  • var result = charAt (test, -1); / / result is ''
  • var result = test.substring (1.5); / / result 'omput'
  • var result = test.toUpperCase (); / / result 'COMPUTER SCIENCE'


Post a Comment