title: Not able to change the position of multiple THREE.Mesh Objects in an array "read only" "undefined"
body: <p>I am learning three.js right now and I did build a small function to create a 3x3x3 grid of cubes.</p>
  <pre><code>let cubes = [];
  
  function createGrid3x3(gridMaterial, positionZ) {
      for( let k = 1; k &lt; 4; k++) {
          for( let j = 1; j &lt; 4; j++) {
  
              //3*3 Layer 
              // j-&gt;
              // k  0 0 0 
              // |  0 0 0  
              // v  0 0 0 
              
              cubes[j*k] = new THREE.Mesh(geometry, gridMaterial);
              cubes[j*k].position.x = j;
              cubes[j*k].position.y = k;
              cubes[j*k].position.z = positionZ;
              scene.add(cubes[j*k]);  
              }
          }
      }
  
  createGrid3x3(material, 1,1);
  createGrid3x3(materialTwo, 2,2);
  createGrid3x3(materialThree, 3,2);
  </code></pre>
  <p>Now I want to animate each of those cubes.</p>
  <pre><code>    const clock = new THREE.Clock()
      
      const tick = () =&gt;
      {
          const elapsedTime = clock.getElapsedTime();
      
          for (var i = 1; i &lt; cubes.length; i++) {
              cubes[i].position.y =  Math.cos(elapsedTime) * i;
  
  OR
  
              cubes[i].position =  Math.cos(elapsedTime) * i;
  
       
          }
       
          // Render
          renderer.render(scene, camera);
      
          // Call tick again on the next frame. 
          window.requestAnimationFrame(tick);
      }
      tick();
  </code></pre>
  <p>Depending on if I use</p>
  <p><code>cubes[i].position.y =  Math.cos(elapsedTime) * i;</code></p>
  <p>OR</p>
  <p><code>cubes[i].position =  Math.cos(elapsedTime) * i;</code></p>
  <p>I get those errors:</p>
  <p><code>Uncaught TypeError: Cannot assign to read-only property 'position' of object '#&lt;Mesh&gt;'</code></p>
  <p>or</p>
  <p><code>Uncaught TypeError: Cannot read properties of undefined (reading 'position')</code></p>
  <p>How can I fix those errors? Why do they appear? I really don't understand why those properties are <code>undefined</code> or <code>read-only</code> if I access them inside an array. If I don't use my function to create those cubes everything works. So I assume it has something to do with the array <code>cubes</code> I created and I don't understand something fundamentally behind it.</p>
  <p>I appreciate your help! :)</p>