Pages

Javascript Array unshift() Method

4/7/14

Description:

Javascript array unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

Syntax:

array.unshift( element1, ..., elementN );
Here is the detail of parameters:
  • element1, ..., elementN : The elements to add to the front of the array.

Return Value:

Returns the length of the new array. This returns undefined in IE browser.

Example:

<html>
<head>
<title>JavaScript Array unshift Method</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");

var length = arr.unshift("water");
document.write("Returned array is : " + arr );
document.write("<br /> Length of the array is : " + length );

</script>
</body>
</html>
This will produce following result:
Returned array is : water,orange,mango,banana,sugar
Length of the array is : 5 
Read more ...

Javascript Array toString() Method

4/7/14

Description:

Javascript array toString() method returns a string representing the source code of the specified array and its elements.

Syntax:

array.toString();
Here is the detail of parameters:
  • NA

Return Value:

Returns a string representing the array.

Example:

<html>
<head>
<title>JavaScript Array toString Method</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");

var str = arr.toString();
document.write("Returned string is : " + str );

</script>
</body>
</html>
This will produce following result:
Returned string is : orange,mango,banana,sugar 
Read more ...

Javascript Array splice() Method

4/7/14

Description:

Javascript array splice() method changes the content of an array, adding new elements while removing old elements.

Syntax:

array.splice(index, howMany, [element1][, ..., elementN]);
Here is the detail of parameters:
  • index : Index at which to start changing the array.
  • howMany : An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed.
  • element1, ..., elementN : The elements to add to the array. If you don't specify any elements, splice simply removes elements from the array.

Return Value:

Returns the extracted array based on the passed parameters.

Example:

<html>
<head>
<title>JavaScript Array splice Method</title>
</head>
<body>
<script type="text/javascript">
var arr = ["orange", "mango", "banana", "sugar", "tea"];

var removed = arr.splice(2, 0, "water");
document.write("After adding 1: " + arr );
document.write("<br />removed is: " + removed);

removed = arr.splice(3, 1);
document.write("<br />After adding 1: " + arr );
document.write("<br />removed is: " + removed);

</script>
</body>
</html>
This will produce following result:
After adding 1: orange,mango,water,banana,sugar,tea
removed is: 
After adding 1: orange,mango,water,sugar,tea
removed is: banana 
Read more ...

Javascript Array sort() Method

4/7/14

Description:

Javascript array sort() method sorts the elements of an array.

Syntax:

array.sort( compareFunction );
Here is the detail of parameters:
  • compareFunction : Specifies a function that defines the sort order. If omitted, the array is sorted lexicographically.

Return Value:

Returns a sorted array.

Example:

<html>
<head>
<title>JavaScript Array sort Method</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");

var sorted = arr.sort();
document.write("Returned string is : " + sorted );

</script>
</body>
</html>
This will produce following result:
Returned array is : banana,mango,orange,sugar 
Read more ...

Javascript Array toSource() Method

4/7/14

Description:

Javascript array toSource() method returns a string representing the source code of the array. This method is supported by Mozilla.

Syntax:

array.toSource();
Here is the detail of parameters:
  • NA

Return Value:

Returns a string representing the source code of the array.

Example:

<html>
<head>
<title>JavaScript Array toSource Method</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");

var str = arr.toSource();
document.write("Returned string is : " + str );

</script>
</body>
</html>
This will produce following result:
Returned string is : ["orange", "mango", "banana", "sugar"]
Read more ...

Javascript Array some() Method

4/7/14

Description:

Javascript array some() method tests whether some element in the array passes the test implemented by the provided function.

Syntax:

array.some(callback[, thisObject]);
Here is the detail of parameters:
  • callback : Function to test for each element.
  • thisObject : Object to use as this when executing callback.

Return Value:

If some element pass the test then it returns true otherwise false.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.some)
{
  Array.prototype.some = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          fun.call(thisp, this[i], i, this))
        return true;
    }

    return false;
  };
}

Example:

<html>
<head>
<title>JavaScript Array some Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.some)
{
  Array.prototype.some = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          fun.call(thisp, this[i], i, this))
        return true;
    }

    return false;
  };
}

function isBigEnough(element, index, array) {
  return (element >= 10);
}

var retval = [2, 5, 8, 1, 4].some(isBigEnough);
document.write("Returned value is : " + retval );

var retval = [12, 5, 8, 1, 4].some(isBigEnough);
document.write("<br />Returned value is : " + retval );
</script>
</body>
</html>
This will produce following result:
Returned value is : false
Returned value is : true 
Read more ...

Javascript Array slice() Method

4/7/14

Description:

Javascript array slice() method extracts a section of an array and returns a new array.

Syntax:

array.slice( begin [,end] );
Here is the detail of parameters:
  • begin : Zero-based index at which to begin extraction. As a negative index, start indicates an offset from the end of the sequence.
  • end : Zero-based index at which to end extraction.

Return Value:

Returns the extracted array based on the passed parameters.

Example:

<html>
<head>
<title>JavaScript Array slice Method</title>
</head>
<body>
<script type="text/javascript">
var arr = ["orange", "mango", "banana", "sugar", "tea"];
document.write("arr.slice( 1, 2) : " + arr.slice( 1, 2) ); 
document.write("<br />arr.slice( 1, 3) : " + arr.slice( 1, 3) ); 
</script>
</body>
</html>
This will produce following result:
arr.slice( 1, 2) : mango
arr.slice( 1, 3) : mango,banana 
Read more ...

Javascript Array shift() Method

4/7/14

Description:

Javascript array shift() method removes the first element from an array and returns that element.

Syntax:

array.shift();
Here is the detail of parameters:
  • NA

Return Value:

Returns the removed single value of the array.

Example:

<html>
<head>
<title>JavaScript Array shift Method</title>
</head>
<body>
<script type="text/javascript">
var element = [105, 1, 2, 3].shift();
document.write("Removed element is : " + element ); 
</script>
</body>
</html>
This will produce following result:
Removed element is : 105 
Read more ...

Javascript Array reverse() Method

4/7/14

Description:

Javascript array reverse() method reverses the element of an array. The first array element becomes the last and the last becomes the first.

Syntax:

array.reverse();
Here is the detail of parameters:
  • NA

Return Value:

Returns the reversed single value of the array.

Example:

<html>
<head>
<title>JavaScript Array reverse Method</title>
</head>
<body>
<script type="text/javascript">
var arr = [0, 1, 2, 3].reverse();
document.write("Reversed array is : " + arr ); 
</script>
</body>
</html>
This will produce following result:
Reversed array is : 3,2,1,0 
Read more ...

Javascript Array reduce() Method

4/7/14

Description:

Javascript array reduce() method applies a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.

Syntax:

array.reduce(callback[, initialValue]);
Here is the detail of parameters:
  • callback : Function to execute on each value in the array.
  • initialValue : Object to use as the first argument to the first call of the callback.

Return Value:

Returns the reduced single value of the array.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.reduce)
{
  Array.prototype.reduce = function(fun /*, initial*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    // no value to return if no initial value and an empty array
    if (len == 0 && arguments.length == 1)
      throw new TypeError();

    var i = 0;
    if (arguments.length >= 2)
    {
      var rv = arguments[1];
    }
    else
    {
      do
      {
        if (i in this)
        {
          rv = this[i++];
          break;
        }

        // if array contains no values, no initial value to return
        if (++i >= len)
          throw new TypeError();
      }
      while (true);
    }

    for (; i < len; i++)
    {
      if (i in this)
        rv = fun.call(null, rv, this[i], i, this);
    }

    return rv;
  };
}

Example:

<html>
<head>
<title>JavaScript Array reduce Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.reduce)
{
  Array.prototype.reduce = function(fun /*, initial*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    // no value to return if no initial value and an empty array
    if (len == 0 && arguments.length == 1)
      throw new TypeError();

    var i = 0;
    if (arguments.length >= 2)
    {
      var rv = arguments[1];
    }
    else
    {
      do
      {
        if (i in this)
        {
          rv = this[i++];
          break;
        }

        // if array contains no values, no initial value to return
        if (++i >= len)
          throw new TypeError();
      }
      while (true);
    }

    for (; i < len; i++)
    {
      if (i in this)
        rv = fun.call(null, rv, this[i], i, this);
    }

    return rv;
  };
}

var total = [0, 1, 2, 3].reduce(function(a, b){ return a + b; });
document.write("total is : " + total ); 
</script>
</body>
</html>
This will produce following result:
total is : 6
Read more ...

Javascript Array push() Method

4/7/14

Description:

Javascript array push() method appends the given element(s) in the last of the array and returns the length of the new array.

Syntax:

array.push(element1, ..., elementN);
Here is the detail of parameters:
  • element1, ..., elementN: The elements to add to the end of the array.

Return Value:

Returns the length of the new array.

Example:

<html>
<head>
<title>JavaScript Array push Method</title>
</head>
<body>
<script type="text/javascript">
var numbers = new Array(1, 4, 9);

var length = numbers.push(10);
document.write("new numbers is : " + numbers ); 

length = numbers.push(20);
document.write("<br />new numbers is : " + numbers ); 
</script>
</body>
</html>
This will produce following result:
new numbers is : 1,4,9,10
new numbers is : 1,4,9,10,20 
Read more ...

Javascript Array pop() Method

4/7/14

Description:

Javascript array pop() method removes the last element from an array and returns that element.

Syntax:

array.pop();
Here is the detail of parameters:
  • NA

Return Value:

Returns the removed element from the array.

Example:

<html>
<head>
<title>JavaScript Array pop Method</title>
</head>
<body>
<script type="text/javascript">
var numbers = [1, 4, 9];

var element = numbers.pop();
document.write("element is : " + element ); 

var element = numbers.pop();
document.write("<br />element is : " + element ); 
</script>
</body>
</html>
This will produce following result:
element is : 9
element is : 4  
Read more ...

Javascript Array map() Method

4/7/14

Description:

Javascript array map() method creates a new array with the results of calling a provided function on every element in this array.

Syntax:

array.map(callback[, thisObject]);
Here is the detail of parameters:
  • callback : Function that produces an element of the new Array from an element of the current one.
  • thisObject : Object to use as this when executing callback.

Return Value:

Returns created array.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        res[i] = fun.call(thisp, this[i], i, this);
    }

    return res;
  };
}

Example:

<html>
<head>
<title>JavaScript Array map Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        res[i] = fun.call(thisp, this[i], i, this);
    }

    return res;
  };
}

var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);

document.write("roots is : " + roots ); 

</script>
</body>
</html>
This will produce following result:
roots is : 1,2,3  
Read more ...

Javascript Array lastIndexOf() Method

4/7/14

Description:

Javascript array lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting atfromIndex.

Syntax:

array.lastIndexOf(searchElement[, fromIndex]);
Here is the detail of parameters:
  • searchElement : Element to locate in the array.
  • fromIndex : The index at which to start searching backwards. Defaults to the array's length, i.e. the whole array will be searched. If the index is greater than or equal to the length of the array, the whole array will be searched. If negative, it is taken as the offset from the end of the array.

Return Value:

Returns index of the found element from the last.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.lastIndexOf)
{
  Array.prototype.lastIndexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]);
    if (isNaN(from))
    {
      from = len - 1;
    }
    else
    {
      from = (from < 0)
           ? Math.ceil(from)
           : Math.floor(from);
      if (from < 0)
        from += len;
      else if (from >= len)
        from = len - 1;
    }

    for (; from > -1; from--)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

Example:

<html>
<head>
<title>JavaScript Array lastIndexOf Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.lastIndexOf)
{
  Array.prototype.lastIndexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]);
    if (isNaN(from))
    {
      from = len - 1;
    }
    else
    {
      from = (from < 0)
           ? Math.ceil(from)
           : Math.floor(from);
      if (from < 0)
        from += len;
      else if (from >= len)
        from = len - 1;
    }

    for (; from > -1; from--)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

var index = [12, 5, 8, 130, 44].lastIndexOf(8);
document.write("index is : " + index ); 

var index = [12, 5, 8, 130, 44, 5].lastIndexOf(5);
document.write("<br />index is : " + index ); 
</script>
</body>
</html>
This will produce following result:
index is : 2
index is : 5  
Read more ...

Javascript Array join() Method

4/7/14

Description:

Javascript array join() method joins all elements of an array into a string.

Syntax:

array.join(separator);
Here is the detail of parameters:
  • separator : Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.

Return Value:

Returns a string after joining all the array elements.

Example:

<html>
<head>
<title>JavaScript Array join Method</title>
</head>
<body>
<script type="text/javascript">

var arr = new Array("First","Second","Third");

var str = arr.join();
document.write("str : " + str ); 

var str = arr.join(", ");
document.write("<br />str : " + str ); 

var str = arr.join(" + ");
document.write("<br />str : " + str ); 
</script>
</body>
</html>
This will produce following result:
str : First,Second,Third
str : First, Second, Third
str : First + Second + Third  
Read more ...

Javascript Array indexOf() Method

4/7/14

Description:

Javascript array indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

Syntax:

array.indexOf(searchElement[, fromIndex]);
Here is the detail of parameters:
  • searchElement : Element to locate in the array.
  • fromIndex : The index at which to begin the search. Defaults to 0, i.e. the whole array will be searched. If the index is greater than or equal to the length of the array, -1 is returned.

Return Value:

Returns the index of the found element.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

Example:

<html>
<head>
<title>JavaScript Array indexOf Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}
var index = [12, 5, 8, 130, 44].indexOf(8);
document.write("index is : " + index ); 

var index = [12, 5, 8, 130, 44].indexOf(13);
document.write("<br />index is : " + index ); 
</script>
</body>
</html>
This will produce following result:
index is : 2
index is : -1 
Read more ...

Javascript Array forEach() Method

4/7/14

Description:

Javascript array forEach() method calls a function for each element in the array.

Syntax:

array.forEach(callback[, thisObject]);
Here is the detail of parameters:
  • callback : Function to test each element of the array.
  • thisObject : Object to use as this when executing callback.

Return Value:

Returns created array.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

Example:

<html>
<head>
<title>JavaScript Array forEach Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

function printBr(element, index, array) {
  document.write("<br />[" + index + "] is " + element ); 
}

[12, 5, 8, 130, 44].forEach(printBr);
  
</script>
</body>
</html>
This will produce following result:
[0] is 12
[1] is 5
[2] is 8
[3] is 130
[4] is 44 
Read more ...

Javascript Array filter() Method

4/7/14

Description:

Javascript array filter() method creates a new array with all elements that pass the test implemented by the provided function.

Syntax:

array.filter(callback[, thisObject]);
Here is the detail of parameters:
  • callback : Function to test each element of the array.
  • thisObject : Object to use as this when executing callback.

Return Value:

Returns created array.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

Example:

<html>
<head>
<title>JavaScript Array filter Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

function isBigEnough(element, index, array) {
  return (element >= 10);
}

var filtered  = [12, 5, 8, 130, 44].filter(isBigEnough);
document.write("Filtered Value : " + filtered ); 
  
</script>
</body>
</html>
This will produce following result:
Filtered Value : 12,130,44 
Read more ...

Javascript Array every Method

4/7/14

Description:

Javascript array every method tests whether all elements in the array pass the test implemented by the provided function.

Syntax:

array.every(callback[, thisObject]);
Here is the detail of parameters:
  • callback : Function to test for each element.
  • thisObject : Object to use as this when executing callback.

Return Value:

Returns true if every element in this array satisfies the provided testing function.

Compatibility:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}

Example:

<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}
function isBigEnough(element, index, array) {
  return (element >= 10);
}

var passed = [12, 5, 8, 130, 44].every(isBigEnough);
document.write("First Test Value : " + passed ); 
  
passed = [12, 54, 18, 130, 44].every(isBigEnough);
document.write("Second Test Value : " + passed ); 
</script>
</body>
</html>
This will produce following result:
First Test Value : falseSecond Test Value : true
Read more ...

Javascript Array concat() Method

4/7/14

Description:

Javascript array concat() method returns a new array comprised of this array joined with two or more arrays.

Syntax:

array.concat(value1, value2, ..., valueN);
Here is the detail of parameters:
  • valueN : Arrays and/or values to concatenate to the resulting array.

Return Value:

Returns the length of the array.

Example:

<html>
<head>
<title>JavaScript Array concat Method</title>
</head>
<body>
<script type="text/javascript">
   var alpha = ["a", "b", "c"];
   var numeric = [1, 2, 3];

   var alphaNumeric = alpha.concat(numeric);
   document.write("alphaNumeric : " + alphaNumeric ); 
</script>
</body>
</html>
This will produce following result:
alphaNumeric : a,b,c,1,2,3 
Read more ...

Javascript String - sup() Method

4/7/14

Description:

This method causes a string to be displayed as a superscript, as if it were in a <sup> tag.

Syntax:

string.sup( )
Here is the detail of parameters:
  • NA

Return Value:

  • Returns the string with <sup> tag.

Example:

<html>
<head>
<title>JavaScript String sup() Method</title>
</head>
<body>
<script type="text/javascript">

var str = new String("Hello world");
alert(str.sup());

</script>
</body>
</html>
This will produce following result:
<sup>Hello world</sup>
Read more ...

Javascript String - sub() Method

4/7/14

Description:

This method causes a string to be displayed as a subscript, as if it were in a <sub> tag.

Syntax:

string.sub( )
Here is the detail of parameters:
  • NA

Return Value:

  • Returns the string with <sub> tag.

Example:

<html>
<head>
<title>JavaScript String sub() Method</title>
</head>
<body>
<script type="text/javascript">

var str = new String("Hello world");
alert(str.sub());

</script>
</body>
</html>
This will produce following result:
<sub>Hello world</sub>
Read more ...

Related Posts