var Bar = function(){
}
Bar.prototype.drawBar = function(obj){
}
var bars = [];// Creating array
for (i = 0;i < ar.length ;i++){
bars[i] = [new Bar(ar[i],i)]; // Creating array of objects
bars[i].drawBar(i);// I am looking for something like this, Currently it doesn't work
}
I have something like this, How do I draw a bar, giving a reference/index, It should draw with the measurements
You are trying to use
bars[i]as if it was aBarobject, but it’s an array of objects.Use this to access the first object in the array:
If you don’t have any use for an array of arrays, just store the objects in the array directly:
Then your original code to access the object works.