What is preventing me from specifying a specific position in my multi-dimensional array?

My goal is to create a 3D version of an L-System, but I'm having trouble declaring elements in my multidimensional array. Even when I try to assign values to specific positions, the elements don't seem to update properly. For instance, if I write something like arraygrowth[0][1] = 100;, the element at that position remains as 0.

let arraygrowth =[];
arraygrowth.push(new THREE.Vector3(0,0,0)); 
arraygrowth.push(new THREE.Vector3(0,0,0));
arraygrowth.push(new THREE.Vector3(0,0,0));

arraygrowth [0][1] = 100;
arraygrowth [1][1] = 100;
arraygrowth [2][1] = 100;

Answer №1

When optimizing your code, the process is similar to this:

let growthArray = [];
growthArray.push(new THREE.Vector3(0,0,0));
growthArray.push(new THREE.Vector3(0,0,0));
growthArray.push(new THREE.Vector3(0,0,0));

growthArray[0].y = 100;
growthArray[1].y = 100;
growthArray[2].y = 100;

This can be simplified as

new THREE.Vector3(0, 0, 0).y = 100;
, which is not the correct way to modify the x, y, z values of a Vector3 object. Accessing arraygrowth[0] returns a Vector3 where you need to use its properties or methods to set the desired value. For instance:

growthArray[0].y = 100; // Assigns y value
growthArray[0].setY(100); // Also assigns y value
growthArray[0].setComponent(1) = 100; // Also assigns y value

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing HTML5 Drag and Drop to jQuery UI Drag and Drop: What's the Difference

In the ever-evolving world of web development, what is the most effective method for creating a drag and drop builder in 2017? While this question has been posed in the past (as seen here), technology changes rapidly. Is HTML5 still the go-to option, or ha ...

The Material UI Select Component has the ability to transform a controlled text input into an uncontrolled one

I encountered a warning in the console while trying to update the value of a Select input. The warning message is as follows: index.js:1446 Warning: A component is changing a controlled input of type text to be uncontrolled. Input elements should not swi ...

Delete property from object in JavaScript

Looking for a solution to replace the content of an object with another in an array of objects without passing the reference directly. The challenge is not knowing what values my function will pass, so I can't use them as keys to avoid copying the re ...

Utilizing React-JS: Leveraging HOC Wrapper to Access a Child Component's Method

I have developed an Editor component that is structured in the following manner: class EditorComp extends Component { focus() { this.refs.input.focus(); } render() { return ( <input ref="input" ... /> ...

How to clear a particular select option in react-bootstrap

I am looking for a solution to clear the second select when the first one selects option B. The clearing should involve removing the value, disabling it, and setting the default option to Select.... import React, { useState } from "react"; import ...

The BottomNavigation component in MUI has a minimum size limit of 400px when it displays 5 items

My issue involves a bottom navigation bar with 5 elements. When the window is resized to less than 400px, the bottom navigation does not shrink, instead maintaining a minimum width of 400px and causing a scrollbar to appear on the x-axis. You can view a m ...

Is it possible to resolve the error message "Uncaught TypeError: Cannot read property 'node' of undefined" when utilizing d3-tip with npm?

After installing d3": "^3.5.17" and "d3-tip": "^0.7.1" via npm (d3-tip documentation), the following code was added to my index.js file: var d3 = require('d3'); var d3tip = require('d3-tip')(d3); console.log('d3 version', d3. ...

JavaScript allows for the insertion of values into either a textbox or dropdown menu

Is there a way to restrict the client from inserting both of these fields: either selecting from a textbox (selected Column) or choosing a value from a dropdown menu (selected Column), but only one field is allowed in a gridview? <asp:GridView ID="gvMe ...

Are you feeling lost when it comes to Javascript? How is it possible for a boolean function to function as a

Preparing for an upcoming interview, I'm diving back into the world of JavaScript. Recently, I came across an interesting blog post that mentioned: "The delete operator returns true if the delete was successful." The blog then provided an example ...

Issue with jSignature transitioning properly from display:none to display:block within a multi-page form

After searching through numerous resources, I have been unable to find a solution to my specific issue. I have a multi-page form that incorporates jSignature as the final tab. The structure closely follows the example from the W3Schools website, tailored t ...

What is the method for extracting a list of properties from an array of objects, excluding any items that contain a particular value?

I have an array of objects, and I want to retrieve a list with a specific property from those objects. However, the values in the list should only include objects that have another property set to a certain value. To clarify, consider the following example ...

JavaScript error caused by incorrect JSON parsing

Encountering Another Issue. Here's the Relevant Code: if(localStorage.getItem("temporaryArray")){ var temporaryArray = JSON.parse(localStorage.getItem("temporaryArray")); }else{ var temporaryArray = []; } Essentially, what this code snippet ...

What is the correct method for downloading an Excel file in a Vue.js application?

I am having difficulty downloading an Excel file in xlsx format using my Vue.js application. The Vue.js application sends a post request to the Node.js application which then downloads the Excel file from a remote SFTP server. The backend application is fu ...

JavaScript code that involves manipulating dates within a nested loop

I'm currently developing a booking system where the pricing varies based on seasons that recur annually. The overall functionality is working smoothly, however, I am encountering difficulties with handling the recurring seasons. I have implemented mom ...

What is the best way to navigate back to the previous state in reactjs?

I have implemented a sidebar component with its initial state set to false in order to hide the block until a user interacts with the hamburger icon. Once clicked, the state changes to true and displays the sidebar menu. However, I am facing an issue whe ...

Breaking Down the Process of Exporting a Next.js Static Website into Manageable Parts

I am facing memory issues while building my website using Next.js's Static HTML Export. The site has a large number of static pages, approximately 10 million. Is it feasible to export these pages in batches, like exporting 100k pages in each build ite ...

Error in jQuery Ajax post request caused by a keyword in the posted data

I understand why the post is failing, but I'm at a loss on how to fix it and I haven't been able to find any solutions online. I am removing references to jEditable in an attempt to simplify things, as this issue occurs even without the jEditable ...

arranging objects based on the distance between them

Here is a JSON array I am working with: var details = [ { 'address':'Pantaloons,701-704, 7th Floor, Skyline Icon Business Park, 86-92 Off A. K. Road,Marol Village, Andheri East,Mumbai, Maharashtra 400059', 'lat':&apos ...

The JQuery category filtering feature malfunctions when a category consists of more than two words

Utilizing Jquery, I have implemented a feature that displays project categories and allows users to filter projects based on the selected category. To view the code pen for this implementation, please click here: https://codepen.io/saintasia/pen/dzqZov H ...

Managing duplicate primary keys in JavaScript applications can be accomplished through various patterns and techniques

I am currently utilizing the npm sequelize library to manage storage utilizing MySQL. The primary key is the Task id, which is generated using the shortid library. What would be an effective Javascript pattern to handle duplicate ids in the rare case that ...