17 May, 2008, 09:17:27 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: We Return!
 

Pages: [1]   Go Down
  Print  
Author Topic: join()  (Read 140 times)
0 Members and 1 Guest are viewing this topic.
rawr


Bronze Contribution
*
Member

Karma: 5
Offline Offline

Gender: Male
Posts: 90
2211.20 Secksi Coins

View Inventory
Send Money to Vitality

View Profile
« on: 27 April, 2008, 06:37:38 AM »

join

The join function is a pretty simple concept to work out. It does exactly what it is called and that is it joins strings. (Strings are text, words, sentences all of that) So, I'll start you off with a basic example, and then show you a variation using another variable in the mix.
Let's get started:

Code:
<script type='text/javascript'>
var rawr = new Array();
rawr[0] = "Me";
rawr[1] = "like";
rawr[2] = "to";
rawr[3] = "code.";
var tcz = rawr.join(" ")
document.write(tcz);
</script>

Ok, let's go through this step by step.

Code:
var rawr = new Array();
We have defined the variable rawr as our array. An array is a set of variables stored into one variable. I like the to think it of like this; the data in the variable is your letter, the variable is our envelope and your array variable is your post office.

Code:
rawr[0] = "Me";
rawr[1] = "like";
rawr[2] = "to";
rawr[3] = "code.";
So, we've stored a bunch of plain text words in our array and that set's up for our next step, joining them all into one sentence.

Code:
var tcz = rawr.join(" ")
This is where our join() function comes into play. We are defining tcz as our variavle to hold our data (the data being joined). So, tcz is going to take the variable from our array rawr and join them into one string. What is between the quotes in the brackets in our join function is what will separate our variables in our new string. In this example, I've just added a space so it shows up like a sentence, but you can always use something different, even <br /> works in there. You could also just leave it as join(), but the default separator is a comma, so it all depends on what you're using this for.

Code:
document.write(tcz);
Last but not least, we will output everything in our document.write(); function. We are writing the joint variables from our rawr array on our page, and believe it or not, that's it. Our outpue will now look like this
Quote
Me like to code.
That about sums up the join() function, but here's another example to show you how it can be implemented even in your IF coding.

Code:
<script>
var url = location.href.split("?");
var rawr = new Array();
rawr[0] = url[0];
rawr[1] = url[1];
rawr[2] = "hey";

tcz = frig.join("<br />")
document.write(tcz);
</script>

This follows the same procedure as the code above, only this time we are joining a split url. To learn more about the split() function, check out my tutorial and take a look at slayer's as well.
So, we are now joining the split url from our variable url, adding the word hey at the end and this time we're separating them with the <br /> tag so it will show up with one piece of text per line. Our output will look like this now
Quote
Wherever your location is part one from where you split it
Wherever your location is part two from where you split it
hey

Well, I hope this tutorial helped you out or at least refreshed you on join(). Enjoy!
Logged

Hey
This resource was found useful by 0 out of 0 members. Rate it: [applaud] [smite]
slayer766United States
Long live TCZ

TCZ r0x my s0x

Administrator

Platinum Contribution
*
Conqueror

Karma: 56
Offline Offline

Gender: Male
Posts: 4419
415595.08 Secksi Coins

View Inventory
Send Money to slayer766

View Profile
« Reply #1 on: 27 April, 2008, 05:21:14 PM »
Take me down to the paradise city where the grass is green and the girls are pretty!

Another great tutorial Vitality. Smiley
Logged

Live for nothing or die for something






rawr


Bronze Contribution
*
Member

Karma: 5
Offline Offline

Gender: Male
Posts: 90
2211.20 Secksi Coins

View Inventory
Send Money to Vitality

View Profile
« Reply #2 on: 27 April, 2008, 06:27:35 PM »

Thanks slayer Cheesy I may work on another one tonight.
Logged

Hey
Pages: [1]   Go Up
  Print  
 
Jump to:  
Sponsored Links:

Powered by MySQL
Powered by PHP
Powered by SMF 1.1.1 | SMF © 2005, Simple Machines LLC
TinyPortal v0.8.6 © Bloc
The rest copyright TCZ you pillocking twat!
Valid XHTML 1.0!
Valid CSS!
Places we'd like you to visit.