Stuck at 0: Apps Script For Loop getting stuck during iteration despite being active

I am currently working with an array called 'vnData' that contains 5 to 6 rows. I am attempting to extract values from the 3rd column based on a certain criteria and insert them into a new array. Below is the code I am using:

for (odr = 0; odr < vnData.length; odr++){
    Logger.log(vnData);
    tempOdr = vnData[odr][3];
    Logger.log(odr);
    Logger.log(tempOdr);
    Logger.log(vnData[odr][3]);
    for(k = 0; k < vnData.length; k++){
      if(vnData[k][3] = tempOdr){
        odrVal = odrVal + vnData[k][11];
      }
    }
    if(odrVal > 0){
      affOdrSet.push(tempOdr);
    }
  Logger.log(affOdrSet);
  }

In my testing, the Logger.log(odr); statement correctly displays the value of odr, but when it comes to Logger.log(vnData[odr][3]);, I always end up with a result where the value of odr is 0.

For each iteration, I seem to be getting the value from the first row. Can anyone help me identify what might be going wrong here?

Additionally, another strange observation I've made is that if I replace Logger.log(vnData[odr][3]) with Logger.log(vnData[3][3]), it gives me the correct value from row 4 in the first iteration. However, in all subsequent iterations, even Logger.log(vnData[3][3]) retrieves the value from the first row, which is quite puzzling.

Answer №1

The issue lies in the first if statement's expression. Rather than

vnData[k][3] = tempOdr

consider using

vnData[k][3] === tempOdr

This adjustment is necessary because = serves as the assignment operator, while it's more probable that you intended to compare tempOdr with vnData[k][3].

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

Moving a Ball Back and Forth Using Three.js

I’m looking to create a continuous motion for a Ball in Three.js, where it moves to the right, returns to its starting position, and then repeats the sequence. var geometry = new THREE.SphereGeometry( 5, 32, 32); var material = new THREE.MeshPhongMateri ...

The issue of AJAX .done() method returning undefined when using $.each() on JSON response

I am having trouble retrieving the JSON response from an $.ajax() request. After selecting a car model, I receive data from the API, but I am unable to access the JSON results to populate a new drop-down list with the required information. HTML <div cl ...

Enhancing features with jQuery's .animate() function

Can anyone help me figure out why the div on the right is not pushing itself away from the one on the left when I hover over it? I want it to move on mouseenter and return to its original position on mouseleave. The changing background colors are just ther ...

Bringing packages from around the world into your Node.js project

In my node.js application, I have several modules where I find myself importing the same package (e.g. moment npm). I'm curious if there is a more efficient way to handle imports by centralizing all dependencies in one place and using them as global ...

What is the best way to eliminate elements from List A that are present in List B?

Two lists have been created as shown below: listA = ['A', 'B','C','D','1','2','3', 'A', 'D','2'] listB = ['A', 'B','C','D ...

Using MySQL or PHP to organize and style groups with tags

Suppose we have an array setup like this pulled from a mysql function: function getGroups($limit = 10) { $data = $this->fetchAll ( 'SELECT gid, `group`, information, tag FROM groups GROUP BY tag LIMIT ' . $limit ); return $data; ...

Access static members from an array or list of objects

Scenario: ClassA { static string c; } ClassB { public List<ClassA> Collection; } .... ClassB b; Is there a way to retrieve the static variable c from ClassA using the object b of type ClassB? ...

I am currently attempting to generate a chart that displays information on countries utilizing the restcountries API. Despite being a beginner in this area, I have encountered some challenges and am seeking guidance

I'm struggling to display detailed information for each country separately. Whenever I try to loop through the data, all the contents end up getting merged into a single cell. What can I do to achieve the desired result? https://i.stack.imgur.com/dZS ...

Sorting and selecting isotopes, with the option to filter or unfilter

All day I've been struggling to find a solution for my isotope filtering issue. I'm using classes from the database to tag items, such as categories and dates, and allowing users to filter them. The tricky part is making these filters work like o ...

After clicking the submit button, make sure to automatically fill in all empty input fields

I am currently working on a form that includes various input types such as text fields, radio buttons, select dropdowns, and text areas. The form is displayed in a table format with an option to add additional rows. One issue I have encountered is that us ...

Struggling to resolve a java.lang.ArrayIndexOutOfBoundsException while trying to solve a shortest path issue

In my attempt to create a for loop that determines a sequence of actions based on the lowest cost, I have established an actions array. The goal is to compare each action in the array with another one, selecting the most cost-effective path and then removi ...

What is the significance of the 'this' context type void not being assignable to type rule?

Currently, I am conducting tests using Typescript to explore the feasibility of a project I have in mind. In one of my functions, I need to specify the type of 'this' as a class. While it technically works, I continue to encounter an error messag ...

Error TS2307: Module '@...' not located during JavaScript compilation

In my current Vue project, I am utilizing VueJs 3 with TypeScript and plan to package the application as a Desktop app using Electron. When running vite, everything functions correctly. However, when I run npm run ts to convert TypeScript files to JavaScr ...

JavaScript objects compared to arrays and JSON format

After countless hours of searching and frustration, I am still struggling to clearly define the distinctions between json, objects, and arrays (in javascript). Take a look at how I've been working with 2-dimensional data containers (trying to avoid us ...

The JavaScript code malfunctions when I introduce a new HTML tag

I am attempting to create a simple photo gallery using PhotoSwipe. However, I have encountered an issue where certain functions like Previous and Next buttons stop working when I add new HTML elements. Here is the original code: <div class="my-gallery ...

Why is the AJAX DELETE Method Redirect Failing to Work?

I'm currently working on troubleshooting my jQuery AJAX call that is triggered by a click on a <a href="#">. This click initiates a DELETE request for a specific URL that I've set up a route for, and then it should redirect to a new page. T ...

"Safari (iOS) is experiencing a functionality issue where Alert() is working, but console.log() is

Just a heads up before you dive in: I've encountered an issue with Safari related to Chrome, but it seems to work fine on other browsers. So, it could be more OS-specific rather than a general problem. I recently ran into a frustrating situation whil ...

React input value doesn't get updated on onChange event causing the input

Currently, I'm working on a React application that requires a table with inputs in each row. To achieve this, I am utilizing Material-UI and Formik. However, I've encountered a bug where input fields lose focus whenever I type something into them ...

Issues have arisen due to server calls being affected by AngularJS routing

I have implemented AngularJS in a nodewebkit application. There are three main views: Home.html Conversation.html Login.html Upon login, the following code is executed: $state.go('home.main'); which triggers the following state c ...

Utilizing ng-repeat Loop Variable in ng-include Content within Angular Framework

I am looking to create two tables with identical record structures. One table will serve as the Main table, while the other will act as an Archive. Each record is represented by bootstrap divs with col-sm-x structure containing details such as {{rec.Name}} ...