-1

I'm new to javascript. So this question might not be good.

var arrQue = new Array(10);
  for (var i = 0; i < 10; i++) {
    arrQue[i] = new Array(6);
  }

This code works perfectly but I wanted to know without giving the array size, how can I make something like this (the following code doesn't work):

var arrQue = new Array();//don't know the size
  for (var i = 0; i < arrQue.length; i++) {
    arrQue[i] = new Array();//don't know the size
  }

And also the code contains two times creating new array. Is there easier or best way to do that creating multiple array?

And later I've to access like this:

arrQue[0][6] = "test";
arrQue[23][3] = "some test";

I found this method but think wrong somehow?

Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};

var arrQue = [];
var size = Object.size(arrQue);
for (var i = 0; i < size; i++) {
   arrQue[i] = [];
   var nextSize = Object.size(arrQue[i]);
}
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231

3 Answers3

4
var arrQue = [];

for (var i = 0; i < length of your inputs; i++) {
    arrQue.push(input);
}

Take a look here

Check out the Array Object Methods there.. that's all the stuff you need.

You can have arrays,arrays of objects... etc..depending upon your requirement.

Nevin Madhukar K
  • 3,031
  • 2
  • 25
  • 52
0
var arrQue = [];
for (var i = 0; i < 10; i++) {
    arrQue.push(input);
}
Amila Iddamalgoda
  • 4,166
  • 11
  • 46
  • 85
0

you might be looking for the push method:

var arr = [];
arr.push(your value);  
Sai Avinash
  • 4,683
  • 17
  • 58
  • 96