Technical Training
JavaScript TutorialJavaScript Array Object Methods
JavaScript Array Object
Methods of Array Object in JavaScript:
There are various methods used with Array object of JavaScript:
- valueOf()
- sort()
- concat()
- join()
- pop()
- push()
- shift()
- reverse()
- slice()
- splice()
- toString()
- unshift()
valueOf():
The method valueOf() of the Array object of JavaScript is used to return the primitive value of an Array object.
NOTE: the valueOf() method of the Array object is usually called automatically by JavaScript and not explicitly by the programmer.
General syntax of the valueOf() method of the Array object of JavaScript:
arrayObject.valueOf()
sort():
The method sort()is used to sort the elements of an array object in JavaScript.
General syntax of the sort() method of the Array object of JavaScript:
arrayObject.sort(sortby)
In the above, the sortby argument is optional. If it is given, it indicates the order in which the sorting must take place which must be defined as a function.
For example:
<body>
<html>
<script type="text/javascript">
var exforsys = new Array(5)
exforsys[0] = "Test"
exforsys[1] = "Welcome"
exforsys[2] = "Training"
exforsys[3] = "Good"
exforsys[4] = "Day"
document.write("The Original Array is:" +"<br />")
document.write(exforsys + "<br />")
document.write("The Sorted Array is:" +"<br />")
document.write(exforsys.sort())
</script>
</body>
</html>
The output of the above example is:
The Original Array is:
Test,Welcome,Training,Good,Day
The Sorted Array is:
Day,Good,Test,Training,Welcome
The first output statement prints the array as such without sorting. The second document.write statement has sort() method defined in it with the Array Object exforsys. Thus, the array is sorted before printing.
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







