H I O X INDIA
Javascript Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
Feedback





Javascript Array Methods


Topic

What are different functions or methods in javascript array?
How can we sort the elements in javascript array?
How to join elements in an array?



Explanation

Array Methods :
        Array has the following predefined methods.

        toString()
        joint()
        reverse()
        sort()

Method: toString() :
        This method is used to convert the array elements in to a string. The string will have each element in the array separated by comma(,).
Example Code:
<script language="javascript">
var varname = new Array();
varname[0] = "testing to string 1";
varname[1] = "testing to string 2";
document.write("toString -- "+varname.toString());
</script>


Result:


Method: join() :
        This method is used to join the elements in the array separated by a separator. This function is much similar to toString method. Here we can specify the delimiter or separator that comes instead of comma.
Example Code:
<script language="javascript">
var aarray = new Array();
aarray[0] = "element 1";
aarray[1] = "element 2";
var xx = aarray.join(" +++ ");
document.write("join() -- "+xx);
</script>


Result:


Method: sort() :
        This method is used for sorting elements in the array. The values will be sorted in a dictionary order.
Example Code:
<script language="javascript">
var sorting = new Array();
sorting[0] = "b for balloon";
sorting[1] = "d for donkey";
sorting[2] = "a for apple";
aarray.sort();
document.write("sort function -- "+sorting.toString());
</script>


Result:


        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

others

privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links