JavaScript string tutorial - String manipulation with JavaScript

Home - Tutorials - Basics

In this tutorial you will learn how to use and manipulate strings in JavaScript.

Tutorial info:

Name:JavaScript string tutorial
Total steps:3
Product:See complete product

Bookmark JavaScript string tutorial

AddThis Social Bookmark Button

Step 2 - String manipulation with JavaScript

JavaScript string tutorial

The most important string manipulation functions are the following:

Now let's see one by one what can we do with them and how to use them in a JavaScript code.


Syntax: object.length; 

This function returns with the total number of characters in the string, or more simple it returns with the length of the string. The usage is quite simple:

  1. var str = 'Demo text.';
  2. var len = str.length;
  3. var len2 = 'my other text'.length;

toLowerCase and toUpperCase 

Synatx: object.toLowerCase(); 

These methods can be very useful if you want to all character in a string lower case or upper case. For example if you want to compare 2 strings but you are not sure if they are capitalized or not. In this case just convert both of them to lower or upper case and you can make the comparison without any problem.

Usage example:

  1. var str = 'Demo Text.';
  2. var strL = str.toLowerCase();
  3. var strU = str.toUpperCase();
  5. if (str.toLowerCase() == 'demo text.')


Synatx: object.charAt(index); 

With this function you can get the character at the given position in a string. If you want you can read the complete string character by character using charAt and a loop. See the examples:

  1. var str = 'Demo Text.';
  2. var c = str.charAt(5);
  4. for (i=0;i<str.length;i++){
  5. alert(str.charAt(i));
  6. }

Previous Step of JavaScript string tutorialNext Step of JavaScript string tutorial

Tags: javascript string functions, javascript string, javascript, string, function

JavaScript string tutorial - Table of contents
Step 1 - JavaScript string basics
Step 2 - String manipulation with JavaScript
Step 3 - More string manipulation functions

GAD Tower

Family tutorials
PHP Array
PHP Redirect
PHP Session
AJAX File Upload
AJAX Rating System
MySQL Create User
Mysqldump Example
MySQL Concat

Total time: 2.9156