How can you use the syntax to refer to two separate arrays in a for loop by using a third array

Apologies if my question is unclear, allow me to clarify:

I have two arrays in 2D format:

const letterA = [ [...],[...],...];
const letterB = [ [...],[...],...];
const letterArray["A","B"];

I want to access them using a for loop like so:

let i = 0;
for(i = 0; i < letterArray.length; i++){
  letter[ letterArray[i] ][foo][foo1]; //This is where I need assistance
}

Can someone please explain the syntax required for this?

Edit: I attempted the following:

eval('letter'+letterArray[i])[j][k]

but I encountered the error:

ReferenceError: letterA is not defined

Answer №1

To resolve the problem, I organized letterA and letterB in a dictionary and utilized it in this manner:

letters = {
letterA : [ [...],[...],...],
letterB : [ [...],[...],...]
};

for(var letter in letters){
    letters[letter][j][k];
}

Appreciation for the assistance, -Jacob

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

What steps are needed to enable autocomplete for input fields in React Native Elements on iOS?

I'm currently working on fine-tuning the autocomplete suggestions for my registration form. Within the react native elements input, I've already implemented fields for username, email, and password. Specifically for the email field, I have config ...

When I try to insert new data into a MongoDB collection during an update operation, the existing data is being overwritten instead

While updating data, I have a requirement to also add new data. Specifically, I need to append data to an existing object in a for loop that stores data in a database. However, when attempting this, the data is being updated instead of added to the current ...

Creating unique geometric designs with three.js

Attempting to construct a polygon in three.js and here is the code used for it. function DeployZone(coordinatesList) { // Forming the polygon Shape { var material = new THREE.MeshLambertMaterial({ color: 0x00ffcc }); var faces = [0, 1, 2, 3, 4] ...

Having trouble resolving errors in Visual Studio Code after failing to properly close a parent function? Learn how to fix this issue

Here we have the code starting with the construct function followed by the parents function public construct() //child { super.construct; } protected construct() //parent { } The issue arises where I am not receiving an er ...

Adding an item to an object array in MongoDB can be achieved with the use of either the addToSet or push operators

I have a set of reviews in an array, and I am trying to implement addToSet functionality to add a review while ensuring that a user can only review once. Below is how my schema is structured: const sellerSchema = new mongoose.Schema({ user: { type: ...

Identify individual cells within a row that share the same ID

I am facing an issue with detecting which cell of a textarea or input text is being changed using the onchange method in my table. The script I have triggers an alert message only for the first row of the table td. For instance, if I add text to the 2nd r ...

Error in hook order occurs when rendering various components

A discrepancy was encountered in React when attempting to render different components Warning: React has detected a change in the order of Hooks called by GenericDialog. This can result in bugs and errors if left unresolved. Previous render Next ren ...

Problem with fetching Grails

I have a table nested within an anchor tag. The table is centered on the page, with each row containing an image. When the page loads, I noticed the following: a) The table initially appears at the top-left corner of the screen. b) As there are multiple v ...

The Android application encountered an issue where the org.json.simple.JSONObject could not be converted to org.json.JSONObject

My task is to sort scores from a JSONArray and display only the top 10. Below is the code I have written. try { JSONArray jArray = new JSONArray(result); List<String> jsonValues = new ArrayList<String>(); for (int i = 0; i < jArray.length ...

PHP query Ajax navigation

UPDATED I have made progress with processing both menus in "process.php" and displaying the queries in index.php. process.php <?php $menu1 = $_POST["menu1"]; $menu2 = $_POST["menu2"]; if($menu1 == 0) { $sql = "SELECT * FROM Language WHERE ID = " ...

Guide to creating a custom wrapper for a Material UI component with React JS

I am utilizing the Material UI next library for my project and currently working with the List component. Due to the beta version of the library, some parameter names are subject to change. To prevent any future issues, I have decided to create a wrapper a ...

The second node child process encounters execution issues in Linux

For a challenge, I needed to find a way to automatically restart my bot within itself. After some trial and error, I came up with a solution. However, when testing on a Raspberry Pi via ssh, the process exits after the first child process ends. Surprisingl ...

Javascript is sometimes unable to access data created by an ajax script

My Jquery Ajax script generates an HTML table in a situation. Another script filters the table column by providing a dropdown with unique values in that specific column. The filter script works fine with static content on the HTML page but is unable to re ...

The rendering of the list is taking an unexpectedly long time due to random factors

I have encountered a strange issue with one of my components. The component fetches a list of objects from a service in the ngOInit(). The problem I am facing seems to occur randomly, where sometimes it takes a considerable amount of time to display this l ...

What to do when rows exceed their size limit in an index?

n=[2 5 50]; nn=720; %total number of angles to consider angle=linspace(-2*pi,2*pi,nn); %array of angles S=zeros(1,nn); for j=1:3 z=n(j); for i=1:nn for k=0:z ns=2*k+1; S(j,i)=S(j,i)+(-1)^k*(angle(j,i))^(ns)/factorial ...

Unable to transfer the output of a react query as a prop to a child

Working on my initial Next.js project, I encountered an issue with the article component that is rendered server-side. To optimize performance and reduce DOM elements, I decided to fetch tags for articles from the client side. Here's what I implemente ...

Firebase firestore is reporting an error stating that the requested document cannot be found

Using nodejs, I am working on creating firestore documents in a specific structure that includes the collection name followed by an ID and then the document itself. While my code successfully adds the document, it does not create the parent document (ID) i ...

Oops! An error occurred while using the Google Maps API. Let's fix this hic

I recently encountered an issue on my website where the Google Map displayed suddenly showed an error message saying: "Oops! Something went wrong. This page didn't load Google Maps correctly. See the JavaScript console for technical details." Afte ...

What are the steps to crafting a personalized message for the valid() method in the JOI library?

To validate the property subscription, I use the following method: Joi.object({ subscription: Joi.string() .valid('starter', 'pro', 'business') .required() .messages({ 'string.base': `{{#label}} s ...

Dynamically load JSON files based on the quantity of files present

Is there a way to load an unknown number of .json files into an array using JavaScript? For example: (in: .../example-folder) abc.json xyz.json uvw.json array.length == 3 (in .../example_folder) abc.json xyz.json array.length == 2 If you are unsur ...