1. concat() - Combine multiple arrays
var myArray1 = new Array("aaa","bbb","ccc");
var myArray2 = new Array("ddd","eee","fff");
var myArray3 = new Array("ggg","hhh","iii");
var myArray4 = myArray1.concat(myArray2,myArray3);
document.write(myArray4);
Output : aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
2. indexOf() - Find an item from first and returns it's position from first.
var myArray2 = new Array("ddd","eee","fff");
var myArray3 = new Array("ggg","hhh","iii");
var myArray4 = myArray1.concat(myArray2,myArray3);
document.write(myArray4);
Output : aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
2. indexOf() - Find an item from first and returns it's position from first.
var myArray = new Array("ppp","qqq","rrr","rrr","kkk");
document.write(myArray.indexOf("rrr"));
Output : 2
3. lastIndexOf() - Find an item from last and returns it's position from last.
document.write(myArray.indexOf("rrr"));
Output : 2
3. lastIndexOf() - Find an item from last and returns it's position from last.
var myArray = new Array("ppp","qqq","rrr","rrr","kkk");
document.write(myArray.indexOf("rrr"));
Output : 3
4. join() - Joins all of the elements in an array into a string (values separated by a comma).
document.write(myArray.indexOf("rrr"));
Output : 3
4. join() - Joins all of the elements in an array into a string (values separated by a comma).
var myArray = new Array("aaa","bbb","ccc");
document.write(myArray.join());
Output : aaa,bbb,ccc
5. slice() - Selects and returns part of an array
document.write(myArray.join());
Output : aaa,bbb,ccc
5. slice() - Selects and returns part of an array
var myArray = new Array("aaa","bbb","ccc","ddd");
document.write(myArray.slice(2,4));
Output : ccc,ddd
6. reverse() - Reverses the order of an array
9. push() - Add items to the end of array
Collected From :
http://www.afterhoursprogramming.com/tutorial/JavaScript/Arrays/
document.write(myArray.slice(2,4));
Output : ccc,ddd
6. reverse() - Reverses the order of an array
var myArray = new Array("aaa","bbb","ccc");
document.write(myArray.reverse());
Output : ccc,bbb,aaa
7. sort() - Sort the order of an array
document.write(myArray.reverse());
Output : ccc,bbb,aaa
7. sort() - Sort the order of an array
var myArray= new Array("ddd","ccc","bbb","aaa");
document.write(myArray.sort());
Output : aaa,bbb,ccc,ddd
8. splice() - Add and/or removes elements from array
document.write(myArray.sort());
Output : aaa,bbb,ccc,ddd
8. splice() - Add and/or removes elements from array
Remove Example :
var myArray1 = new Array("aaa","bbb","ccc","ddd");
myArray1.splice(2,1);
document.write(myArray1);
Add Example :
var myArray2= new Array("aaa","bbb","ccc","ddd");
myArray2.splice(1,1,"eee","fff");
document.write(myArray2);
Output 1: aaa,bbb,ddd
Output 2: aaa,eee,fff,ccc,ddd
var myArray1 = new Array("aaa","bbb","ccc","ddd");
myArray1.splice(2,1);
document.write(myArray1);
Add Example :
var myArray2= new Array("aaa","bbb","ccc","ddd");
myArray2.splice(1,1,"eee","fff");
document.write(myArray2);
Output 1: aaa,bbb,ddd
Output 2: aaa,eee,fff,ccc,ddd
9. push() - Add items to the end of array
var myArray = new Array("aaa","bbb","ccc");
myArray.push("ddd");
document.write(myArray);
myArray.push("ddd");
document.write(myArray);
Output : aaa,bbb,ccc,ddd
10. pop() - Removes the last item of an array
10. pop() - Removes the last item of an array
var myArray = new Array("aaa","bbb","ccc");
myArray.pop();
document.write(myArray);
myArray.pop();
document.write(myArray);
Output : aaa,bbb
11. shift() - Removes the first item of an array
11. shift() - Removes the first item of an array
var myArray = new Array("aaa","bbb","ccc");
myArray.shift();
document.write(myArray);
myArray.shift();
document.write(myArray);
Output : bbb,ccc
12. unshift() - Adds item to beginning of an array
12. unshift() - Adds item to beginning of an array
var myArray = new Array("aaa","bbb","ccc");
myArray.unshift("zzz");
document.write(myArray);
myArray.unshift("zzz");
document.write(myArray);
Output : zzz,aaa,bbb,ccc
Collected From :
http://www.afterhoursprogramming.com/tutorial/JavaScript/Arrays/