Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    193
    Thanks
    147
    Thanked 0 Times in 0 Posts

    Building a javascript data array

    Hello,

    I really need your help,

    How can the JavaScript code below, be re-formatted such that the array data is output into the following format as follows?

    Code:
    var data =
        [
            [1,'Crystal','Johnson','active'],
            [2,'Ricky','Bobby','closed'],
            [3,'Susan','Spencer','closed'],
            [4,'Kyle','Black','active']
        ]
    The code below as it stands currently builds the data in the following format:

    Code:
    Crystal,Johnson,active,Ricky,Bobby,closed,Susan,Spencer,closed,Kyle,Black,active
    It seems close, but the line counter somehow needs to be integrated and put in the proper format per the first example above

    Here is the code that builds the array in question:

    Code:
    function test() {
    
        var data = [];
    
        while (!rs.eof) {
    
            for (var i = 0; i < rs.fields.count; ++i) {
    
                data.push([rs.fields(i).value]);
            }
    
            rs.MoveNext
        }
    
        alert(data) 
    
    }

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,690
    Thanks
    25
    Thanked 656 Times in 655 Posts
    What are you reading? while (!rs.eof) sugests a text file. Anyway try this:
    while (!rs.eof) {
    for (var i = 0; i < 4; ++i) {
    Or is this a variable
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Code:
    data.push([i, rs.fields(i).value]);
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    function test() {
        var data = [],
        	ctr = 1,
        	record = [];
    
        while (!rs.eof) {
        	record.push(ctr);
            for (var i = 0; i < rs.fields.count; ++i) {
                record.push(rs.fields(i).value);
            }
            data.push(record);
            ctr++;
            rs.MoveNext
        }
    
        alert(data);
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •