Derick Kolln
Derick Kolln

Reputation: 633

Get access to the right element in the Array

I am using the for-loop below:

console.log(a1); 
 for(var f = 0; f < a1.length; f++){

 b= a1[f];

console.log(b);............

My console shows me this:

  Array [ Array[6], Array[8] ] 
  Array [ Object, Object, Object, Object, Object, Object ] 
  Array [ Object, Object, Object, Object, Object, Object, Object, Object]

Now, the first Array line in the console is console.log(a1) and the other 2 Arrays are console.log(b).

I want to get access to the whole first Array of console.log(b) only. I tried to use console.log(b[0]), but this shows me only the first objects including their properties of the 2 Arrays, but I want to see the full first Array with the 6 elements only on my console. Can someone help me to solve?

Upvotes: 0

Views: 80

Answers (1)

Botimoo
Botimoo

Reputation: 599

As I understand you want to work with the first array of objects, which is the first element of a1, so you need to loop through a1[0] which gives you the first array as wanted:

for(var f = 0; f < a1[0].length; f++) {
    var b = a1[0][f];
    console.log(b);
    //do stuff here
}

Upvotes: 1

Related Questions