Creating an Array Literal using a large recordset from a database

S

shookim

The correct syntax for an array literal would be:

this.managers [ "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W" ];

(which works)

My questioin is, how do you recreate this same syntax pulling from a
recordset containing over 3500 records such as:

aManagerName = "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W", etc...

because

this.managers [ aManagerName ];

(does not work)
 
S

shookim

Resolved this issue. The problem is, it wasn't reading as javascript
code...changed the code to:

eval('this.managers = [' + aManagerName + ']')

and it worked!
 
V

VK

The correct syntax for an array literal would be:

this.managers [ "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W" ];

(which works)

My questioin is, how do you recreate this same syntax pulling from a
recordset containing over 3500 records such as:

aManagerName = "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W", etc...

because

this.managers [ aManagerName ];

(does not work)

The situation is not clear. Where exactly aManagerName is located? If
inside JavaScript program then it doesn't have sense:

<script type="text/javascript">
aManagerName = "DOE, JANE", "DOE, JOHN", "DOE, WILMA";
</script>

is a set of comma-operators. After execution of this string
aManagerName will contain the rightmost string "DOE, WILMA". All other
values will be lost. If it's not the case than please provide more
details.
 
S

shookim

well...it was really in a function that was being called from another
function and quite complicated piece of code. The resolution I posted
was that I was originally having my recordset loop through and create a
string, which I then added some quotations and commas to make it appear
like a javascript array literal. The problem was it was reading it as
a string versus as a comma-deliminited array. I added the eval
function and it read aManagerName as javascript code.

Hope that helps.
sk
 
T

Thomas 'PointedEars' Lahn

Resolved this issue. The problem is, it wasn't reading as javascript
code...changed the code to:

eval('this.managers = [' + aManagerName + ']')

and it worked!

Whatever you are trying to do, most certainly it can be done without
evil[tm] eval().


PointedEars
 
U

UnaCoder

Your question isn't very clear, what I assume you are trying to do is
copy the content of one array into another. The correct method to do
this would be with some sort of a loop to copy each value. I would
personally use a for loop:

var array1 = [ "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W" ];
var array2 = new Array;

for (var i = 0; i < array1.length; i++) { array2 = array1; }

Never use Eval.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Thu, 16 Feb 2006 08:31:00 remote, seen in
news:comp.lang.javascript said:
Your question isn't very clear, what I assume you are trying to do is
copy the content of one array into another. The correct method to do
this would be with some sort of a loop to copy each value. I would
personally use a for loop:

var array1 = [ "DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W" ];
var array2 = new Array;

for (var i = 0; i < array1.length; i++) { array2 = array1; }


The variable aManagerName is very probably a string. In that case,
..split() with a suitable RegExp parameter should do what is required.


aManagerName = '"DOE, JANE", "DOE, JOHN", "BUSH, GEORGE W"'

X = aManagerName.split(/"(, )?/)
// X now ["DOE, JANE", "DOE, JOHN," "BUSH, GEORGE W"]
X = X.join(' + ') // for demo
// X now "DOE, JANE + DOE, JOHN + BUSH, GEORGE W"

It is possible that some browsers may give an empty element at each end
of the array. If so, remove the variation by adding a dummy character
to each end of the string before splitting it.

Never use Eval.

There is absolutely hardly anything wrong with using "Eval". But "eval"
is appropriate less often than it is used. See the newsgroup FAQ on the
subject.


Your knowledge of javascript, and of computing in general, appears
inadequate to justify your attempting to answer questions on the topic.
Continue with your courses, gain some real experience, and you may
become able to offer worthwhile assistance. When you know as much as
VK, you'll be about half way to being useful.

Before responding again, find out how to quote in Google, or move to
proper news software.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top