473,378 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Returning the complete contents of an array to another function

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
2 19400
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
8
by: darren | last post by:
Hi everybody, have a quick look at this code: ===== ===== int main(void) { string msg; makeString(msg); cout << "back in main, result = " << msg << endl;
5
by: Cromulent | last post by:
Okay I'm having a few issues with this and I can't seem to get it sorted out (most likely due to my inexperience with Python). Here is my Python code: def fileInput(): data = s =...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.