Returning the complete contents of an array to another function

C

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
 
L

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>
 
C

CES

Lee,
That was 3 hours out of my life...
Thank You.
CES
Lee said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top