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
    184
    Thanks
    140
    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,105
    Thanks
    23
    Thanked 594 Times in 593 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,301
    Thanks
    10
    Thanked 586 Times in 567 Posts
    Code:
    data.push([i, rs.fields(i).value]);
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 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);
    }


  •  

    Posting Permissions

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