Thursday, April 14, 2011

How to add, remove, and chage content of the Array in Java Script (splice(start, delete,element1,element2,…)):


<script language="javascript">

Arr1=new Array("RED","YELLOW","GREEN","BLUE","WHITE","BLACK") ;
Arr1.splice(1,0,"PINK","ORANGE");
/*If you put 1 in place of 0 then one element will be removed from the array and if you put 0 inplace of 1
elements added from the begining of the array */
for(i=0;i<Arr1.length;i++)
{
document.write(Arr1[i]+"<br/>");
}

No comments:

Post a Comment