Saturday, January 28, 2012

How to use sup() and sort() Method in JavaScript

The sup() method in JavaScript

The sup() method is used to display a string as superscript text.

Syntax: string.sup();

JavaScript Code:
 
<script language="javascript">
function supWin()
{
    var myString = new String('Two'); 
    document.write('Square'+myString.sup());
}
</script>

HTML Code:
<button onclick=”this. supWin();”>Click here!! </button>

How to use sort() Method in JavaScript

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

Syntax: array.sort(sortfunc);

JavaScrip Code:

<script language="javascript">
function sortArray()
{
    var myString = new Array('Anil','Singh','Kushinagar'); 
    myString.sort();
    alert(myString);
}
</script>

HTML Code:
<button onclick="sortArray()">Sort Array</button>

No comments: