WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Javascript - Shift , Slice, Splice Empty Javascript - Shift , Slice, Splice Sun May 20, 2012 4:33 am

Mr.Joker

Mr.Joker
Mr. WebArtz
Mr. WebArtz
Hello WebArtz members, I am Mr.Joker and in this tutorial I will show you how to use methods as Shift, Slice and Splice. Its not difficult because you allready know how methods work allready. Here we go:

1. Shift : With shift method you remove first parameter form array. Here si one example:

Code:
 <script type="text/javascript">
var color = new Array("red","blue","green")
color.shift()
document.write(color);
 </script>

Lets explain code a bit. We have here one Array with parameters red, blue and green. In next row I say :
Array_name.method()
Like that, i just removed the first element or parameter of Array. In last code line i just show the result.

2. Slice : With slice method you can select how many elements of array will be printed on screen. I can say it will be printed first two, or, second till end and so on with combinations. Example:

Code:
 <script type="text/javascript">
var color = new Array("red","blue","green","orange","yellow")
var x = color.slice(0,3)
document.write(x);
 </script>

Here we have one Array with 5 elements. I created another variable caled "x" and inside it i said that Array color will be sliced from begining till element no.3 in Array. So this mean that document will print out Only first 3 elements of Array, but not the 4 as last parameter say. So if its 3 last that doesent mean it will be counted, its not counting that one.

3. Splice: With splice you can remove all other items and then print only the one you picked.

Code:
 <script type="text/javascript">
var color = new Array("red","blue","green","orange","yellow")
var x = color.splice(1,2)
document.write(x);
 </script>

Code is quite simple. Array contain 5 elements. When you type color.splice(1,2) that mean that first two elements will be printed and all other will not.

Thats all for now, If you have any questions you can ask me Wink

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum