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
    202
    Thanks
    152
    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. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,282
    Thanks
    30
    Thanked 863 Times in 861 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.
    Physics is actually atoms trying to understand themselves.

  3. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,646
    Thanks
    11
    Thanked 626 Times in 605 Posts
    Code:
    data.push([i, rs.fields(i).value]);
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  4. #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
  •