1 Javascript - Pop, Push, Reverse, Join methods Wed May 09, 2012 4:56 pm
Mr.Joker
Mr. WebArtz
Hello once more, I am Mr.Joker and in this tutorial you will learn very important methods as Pop, Push, Reverse, Join and Sort. Lets begin:
-Pop : With pop method you can delete the last "member" or Array. So if array is like (1,2,3,4,5) and you use pop , number 5 will be deleted. Here is example:
-Push : With push method you can add another element inside array. You can do it on simple way like this:
-Reverse : With reverse method we can reverse order inside Array so that mean that last element will be first now, and first will be last and so on. Example:
-Join : With join method you can join all elelments of array with some sign. For example:
-Sort : With sort method you can sort all elements of Array by alphabetic order. For example:
Thats all in this tutorial, hope you like it, you can always ask if you need help.
-Pop : With pop method you can delete the last "member" or Array. So if array is like (1,2,3,4,5) and you use pop , number 5 will be deleted. Here is example:
- Code:
<script type="text/javascript">
var x = new Array(1,2,3,4,5);
x.pop()
document.write(x)
</script>
-Push : With push method you can add another element inside array. You can do it on simple way like this:
- Code:
<script type="text/javascript">
var x = new Array(1,2,3,4,5);
x.push(6)
document.write(x)
</script>
- Code:
<script type="text/javascript">
var x = new Array(1,2,3,4,5);
for (i=0;i<3;i++) {
var question = new Array()
question[i] = window.prompt("Enter a number to add in Array:")
x.push(question[i])
}
document.write(x)
</script>
-Reverse : With reverse method we can reverse order inside Array so that mean that last element will be first now, and first will be last and so on. Example:
- Code:
<script type="text/javascript">
var x = new Array(1,2,3,4,5);
x.reverse()
document.write(x)
</script>
-Join : With join method you can join all elelments of array with some sign. For example:
- Code:
<script type="text/javascript">
var x = new Array(1,2,3,4,5);
var y = x.join("-")
document.write(y)
</script>
1-2-3-4-5
-Sort : With sort method you can sort all elements of Array by alphabetic order. For example:
- Code:
<script type="text/javascript">
var x = new Array("Devil","Test","Angel")
var y = x.sort()
document.write(y)
</script>
Thats all in this tutorial, hope you like it, you can always ask if you need help.
Last edited by Mr.Joker on Thu May 10, 2012 5:13 am; edited 1 time in total