Ø join()
· The join() method is used to put all the elements of an array into string.
· The elements will be separated by a specified separator.
· Comma is the default separator for the join() method.
Syntax : arrayobject.join([separator])
Parameter | Description |
Separator | Optional, Specifies the separator to be used. |
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x.join()+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
Ø reverse()
· The reverse() method is used to reverse the order of the elements in an array.
Syntax : arrayobject.reverse()
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x+"<br/>");
document.write(x.reverse()+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
C++,vb,php
Ø pop()
· The pop() method is used to remove and return the last element of an array.
· This method change the length of the array.
Syntax : arrayobject.pop()
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x+"<br/>");
document.write(x.pop()+"<br/>");
document.write(x+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
C++
Php,vb
Ø push()
· The push() method adds one or more elements to the end of an array and return the new length.
Syntax : arrayobject.push(newelement1,[newelement2…….,newelementn])
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x+"<br/>");
x.push("java");
document.write(x+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
Php,vb,c++,java
Ø shift()
· The shift() method is used to remove and return the first element of an array.
· This method change the length of array.
Syntax : arrayobject.shift()
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x+"<br/>");
document.write(x.shift()+"<br/>");
document.write(x+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
vb,c++
Ø sort()
· The sort() method is used to sort the element of an array.
Syntax : arrayobject.sort()
Example
<html>
<head>
<script language="javascript">
var x = new Array(3);
x[0] = "php";
x[1] = "vb";
x[2] = "c++";
document.write(x+"<br/>");
document.write(x.sort()+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++
c++,php,vb
Ø concat()
· This function will join two or more than two arrays.
Syntax : arrayobject.concat(array1,array2…….)
Example
<html>
<head>
<script language="javascript">
var x = new Array("php","vb","c++");
var y = new Array(1,2,3);
document.write(x.concat(y)+"<br/>");
</script>
</head>
</html>
Output
Php,vb,c++,1,2,3
Posted By : Hemangi Zala
No comments:
Post a Comment