By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Returning the complete contents of an array to another function

P: n/a
CES
All,

Sorry for the 101 question but I can't figure out how to return all of the
contents of an array to another function. I been able to figure out how to
return individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.
CES
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
CES said:

All,

Sorry for the 101 question but I can't figure out how to return all of the
contents of an array to another function. I been able to figure out how to
return individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.


Your argument passing is fine as written.
Don't call document.write() in the body's onload handler.
That makes the page load, and then changes the contents.
It's better to call your function as the body is loading:
<html>
<head>
<title></title>
<script type="text/javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");
return newArray;
}

function test(){
document.write(tmp())
}
</script>
</head>
<body>
<script type="text/javascript">
test();
</script>

</body>
</html>

Jul 20 '05 #2

P: n/a
CES
Lee,
That was 3 hours out of my life...
Thank You.
CES
"Lee" <RE**************@cox.net> wrote in message
news:bl********@drn.newsguy.com...
CES said:

All,

Sorry for the 101 question but I can't figure out how to return all of thecontents of an array to another function. I been able to figure out how toreturn individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.


Your argument passing is fine as written.
Don't call document.write() in the body's onload handler.
That makes the page load, and then changes the contents.
It's better to call your function as the body is loading:
<html>
<head>
<title></title>
<script type="text/javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");
return newArray;
}

function test(){
document.write(tmp())
}
</script>
</head>
<body>
<script type="text/javascript">
test();
</script>

</body>
</html>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.