Creating an Array Literal using a large recordset from a database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shookim@gmail.com

    Creating an Array Literal using a large recordset from a database

    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)

  • shookim@gmail.com

    #2
    Re: Creating an Array Literal using a large recordset from a database

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

    eval('this.mana gers = [' + aManagerName + ']')

    and it worked!

    Comment

    • VK

      #3
      Re: Creating an Array Literal using a large recordset from a database


      shookim@gmail.c om wrote:[color=blue]
      > 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)[/color]

      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.

      Comment

      • shookim@gmail.com

        #4
        Re: Creating an Array Literal using a large recordset from a database

        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

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Creating an Array Literal using a large recordset from a database

          shookim@gmail.c om wrote:
          [color=blue]
          > Resolved this issue. The problem is, it wasn't reading as javascript
          > code...changed the code to:
          >
          > eval('this.mana gers = [' + aManagerName + ']')
          >
          > and it worked![/color]

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


          PointedEars

          Comment

          • UnaCoder

            #6
            Re: Creating an Array Literal using a large recordset from a database

            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[i] = array1[i]; }

            Never use Eval.

            Comment

            • Dr John Stockton

              #7
              Re: Creating an Array Literal using a large recordset from a database

              JRS: In article <1140107460.124 016.291420@f14g 2000cwb.googleg roups.com>
              , dated Thu, 16 Feb 2006 08:31:00 remote, seen in
              news:comp.lang. javascript, UnaCoder <unacoder@gmail .com> posted :[color=blue]
              >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[i] = array1[i]; }[/color]

              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.sp lit(/"(, )?/)
              // 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.

              [color=blue]
              >Never use Eval.[/color]

              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.

              --
              © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
              Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
              Check boilerplate spelling -- error is a public sign of incompetence.
              Never fully trust an article from a poster who gives no full real name.

              Comment

              Working...