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

Login with username, password and session length
News: We Return!
 
 Ad by
Pages: [1]   Go Down
  Print  
Author Topic: push()  (Read 126 times)
0 Members and 1 Guest are viewing this topic.
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
« on: 05 May, 2008, 04:47:56 AM »
Take me down to the paradise city where the grass is green and the girls are pretty!

JavaScript has a built in push() function which allows a coder to add more arrays to an existing array. So lets say we have an array like so:

Code:
<script type="text/javascript">
//push() explanation

var Set = [];
Set[0] = ["Wow"]
Set[1] = ["this"]
Set[2] = ["is"]

document.write(Set);
</script>
Now anyone who knows how an array works would know that this would write out Wow,this,is

Ok, now for the function push() this method is very simple to understand and you can pass this function MANY parameters. The function is set-up like this:

Code:
<script type="text/javascript">
//push() explanation

var Set = [];
Set[0] = ["Wow"]
Set[1] = ["this"]
Set[2] = ["is"]

Set.push("crazy");

document.write(Set);
</script>

Now you see that we've basically appended the word "crazy" to the existing array. Which now the array would output like so:

Wow,this,is,crazy


That's all the push() method is about, nothing extreme, but quite useful. Smiley
Logged

Live for nothing or die for something






This resource was found useful by 0 out of 0 members. Rate it: [applaud] [smite]
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 #1 on: 05 May, 2008, 04:57:38 AM »

I've seen push() a bunch of times, but never new what i was. Simple to understand, and clear tutorial. Nice one slayer Wink
Logged

Hey
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 #2 on: 05 May, 2008, 05:05:46 AM »
"We know what we are, but know not what we may become." - William Shakespeare

Thanks. Cheesy I've never used it though, just thought I might write one up. ^_^
Logged

Live for nothing or die for something






ChireruUnited States
We are all desprate to find our meaning in life

when we have always known our meaning

Code Trainee

Platinum Contribution
*
Hero Member

Karma: 11
Offline Offline

Gender: Male
Posts: 784
309.29 Secksi Coins

View Inventory
Send Money to Chireru

View Profile WWW
« Reply #3 on: 11 May, 2008, 01:08:04 AM »

AWESOME
BEST THING EVER

oh yeah, you can also do something like this

document.write(set+"crazy");

LOL

sorry, my smartass impulse was just too much to resist
lol
Logged




join today
we've got many codes and services for you
Current Projects:
Skin Generator v1
Hellfire RPG

Hellfire RPG Forums

You can take away everything from me, but you better fucking run if you give me a living hell.
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 #4 on: 11 May, 2008, 03:22:18 AM »
Take me down to the paradise city where the grass is green and the girls are pretty!

Yes adding just something simple like text to an array you can also do that, but if you wanted something more complex of push you would do something like this:

Code:
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
Logged

Live for nothing or die for something






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.