Why I don't see the loging properties only the length value?

Hello,

I try to push() an array properties to another array with for{} loop and when I console log() the outcome I only see the number of properties and not the acual value - The array - “Bob”, “Dylan”, 67

 var myArr = ["Bob","Dylan",67];
 var total = [];
        
 for(i=0; i<myArr.length; i++){
   total.push(i);
 }
 
console.log(total);

Instead of pushing just i, which is the iterator, try pushing myArr[i], which is the value of myArr at index i.

total.push(myArr[i]);

1 Like

But you aren’t pushing the array elements, you are pushing your iteration variable, i.

total.push(i);

If you want to push your array elements, it would have to be:

total.push(myArr[i]);
1 Like