JavaScript - Can not access the first element of the array

advertisements

I am trying to access the first element of the array using the following:

array[0];

The format of the array

var array = [[Object { userId: "FqOANa1w2f", currentLocation: Object }],[Object { userId: "FqOANa1w2f", currentLocation: Object }]]

However, when trying to do a:

  console.log(array[0]);

I get undefined.

and when running:

 console.log(array)

it shows the array contents.

Any ideas on what's going on?


They should have been like this syntax from backend:

var array = [
  { userId: "FqOANa1w2f", currentLocation: Object },
  { userId: "FqOANa1w2f", currentLocation: Object }
];

var array2 = [
 [{ userId: "FqOANa1w2f", currentLocation: Object }],
 [{ userId: "FqOANa1w2f", currentLocation: Object }]
];

console.log(array);
console.log(array2);