...

View Full Version : What does 'push' do?



Mike1985
10-13-2011, 03:47 PM
Hi..

I have some code I wrote a while ago and now I can't remember what it does!



var subArray = [];
subArray[0] = frontEndOptionsId;
subArray[1] = document.getElementById(frontEndOptionsId).value;
BYOT5.push(subArray);


And further down I have...



xh.sendRequest("GET","/byot5.php",BYOT5,callback,false);


Am I right in guessing that the 'push' pushes the elements in subArray in to BYOT5 in my second segment? Would it look like...



xh.sendRequest("GET","/byot5.php",subArray("ZERO","ONE"),callback,false);


...when it's sent to byot5.php? Or am I completely wrong?! :confused:

niralsoni
10-13-2011, 05:07 PM
Push and Pop methods are associated with Array object, to represent the functionality of STACK.

in your case, BYOT5.push(subArray) represents a two-dimensional array, something like shown below -
[
[frontEndOptionsId, document.getElementById(frontEndOptionsId).value]
];

Old Pedant
10-13-2011, 07:44 PM
Mike:

subArray("ZERO","ONE") is meaningless.

It might be clearer to say that this:


xh.sendRequest("GET","/byot5.php",BYOT5,callback,false)

is the same as this:


xh.sendRequest(
"GET",
"/byot5.php",
[
[ frontEndOptionsId, document.getElementById(frontEndOptionsId).value ]
],
callback,
false)

In other words, BYOT is an array of arrays. It happens that the outer array only has one element (unless you didn't show us all the push() calls?) and the inner array that is that one element in turn has two elements.

Old Pedant
10-13-2011, 07:49 PM
And as to what actually happens: You don't show us the code for sendRequest( ) but assuming you are making an AJAX call, then the *actual* call to PHP will be done something like this, almost surely:

Let's say that frontEndOptionsId is the string "zamboni".

And somewhere in your HTML you have something like

<input id="zamboni" />
and the user types in "froozle" to that text field.

So, then, you will end up doing


xh.sendRequest(
"GET",
"/byot5.php",
[
[ "zamboni", "froozle" ]
],
callback,
false)
and I'll bet a small latte that sendRequest will end up using the url:


/byot5.php?zamboni=froozle



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum