-1

I have this array called "players" which stores all the players, each element of this array contains each individual player stored as an object, and this player object contains a property called "time" which in it of itself is an array. When ever I try to push an integer into this time array, I get a "time.push() is not a function" error.

players[data.num].time.push(uptime());

what I am attempting here is array[index].array.push()

This array is undefined and is declared like this.time = []; The player objects were made by constructor function as well.

Here are the other arrays I mentioned before;

var players = [];
players.push(new Player(0,0,true));

Player() is a constructor function that contains this.time = [];

Any help is appreciated.

Canatron
  • 85
  • 11

2 Answers2

0

I base my answer upon that you have an array of objects with another array in each object. Then this should work.

var objs = [{array:[]},{array:[]},{array:[]}]

objs[0].array.push("test");

console.log(objs)

http://jsbin.com/romubeyoyu/edit?js,console

ffffff01
  • 5,068
  • 11
  • 52
  • 61
0

Very stupid mistake.

this.time = [];

and just a few lines later...

this.time = 0;

I created the former this.time = 0; for animation, I forgot about it when making this array and as you know, you cannot push into and int variable.

Sorry for causing all the trouble...

Canatron
  • 85
  • 11