monitoring
Closed Thread
Results 1 to 3 of 3

Thread: Java Script Populating 2D array thought prompt???

  1. #1
    Join Date
    Jan 2012
    Posts
    5

    Talking Java Script Populating 2D array thought prompt???

    Hey I need to make a simple program which consists of insert function which adds the data asked for to 2D array.. I think i did the array but I am not right sure
    (data to be entered in name, height, weight,)

    Code:
    Code:
    var person = new Array(i)
    for (var h = 0; h < i; h++)
    person[i] = new Array(j);
    I know that one dimension is going to be * but not sure which is the horizontal the vertical has to be undefined since this will be like a small database and i dont know how much data will be added.

    also how do i make the insertion function ? could i do something like

    Code:
    Code:
    var createPerson =function(name,height,weight){
    var person = {}
    person.name = name
    person.height = height
    person.weight = weight
    return person
    };
    
    var person = {name: "James Bond",height: "0", weight: "0"};
    I am really confused at this stage.. not sure how to do this any ideas ?

  2. #2
    Join Date
    Jan 2012
    Posts
    5

    Lightbulb

    Hello there,

    Get a random value in between * and *00 (num*). Add it to the array. Find another random value from * to (*00 - num*) (num2). Add it to the array. Etc. Continue until the array size is 4. The last element should be *00 - the sum of the 4 numbers. Add that array to the bigger array.

    Regards,
    Jackie

    _________________
    Last edited by DougN; 09-06-2012 at 04:47 PM.

  3. #3
    miketaylor Guest
    I just noticed too, when i was trying to implement a 2D array into JS. It is Screwed. But here is a solution if you want to stick to multidimensional arrays: An Object.

    function Array2D() {
    function setArray(length) { // set an array inside the object
    this.elem=new Array();
    for(i=0;i<length;i++) {
    this.elem[i]=null;
    }
    }
    this.setArray=setArray;
    this.elem=null; // our array
    }

    With this little fella you can hide your intentions from the Evil Javascript Developers, and secretly make a 2D array:

    arr = new Array();
    arr[0] = new Array2D();
    arr[0].setArray(2);
    arr[0].elem[0] = "Hy, ";
    arr[0].elem[*] = "I'm ";
    arr[*] = new Array2D();
    arr[*].setArray(2);
    arr[*].elem[0] = "Da";
    arr[*].elem[*] = "vid!";

    alert(arr[0].elem[0] + arr[0].elem[*] + arr[*].elem[0] + arr[*].elem[*]); // this will say "Hy, I'm David!"

    *******************
    Last edited by DougN; 09-06-2012 at 04:47 PM.

Closed Thread

Similar Threads

  1. Array of Hope
    By JayT in forum Programming
    Replies: 9
    Last Post: 03-25-2008, 04:49 PM
  2. Array Of Hope
    By JayT in forum Programming
    Replies: 3
    Last Post: 09-27-2007, 10:49 PM
  3. command prompt
    By Unregistered in forum Internet Privacy
    Replies: 1
    Last Post: 02-13-2005, 01:45 AM

Posting Permissions

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