Trying to match an individual variable with every single value in a list

I recently created a script for a Google Sheet that involves taking user input and comparing it to values already on the spreadsheet.

Within the function below, I captured the user's desired number using the variable voltReqed.

My goal is to compare this value (checking if it is less than or greater than) with each number in an array generated by the variable voltCompareData.

As I am still learning about scripts, I appreciate your understanding of any mistakes I may make.

function getVoltage() {
  var voltReqed = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("A1").getValue();
  Logger.log(voltReqed);
  var voltCompareData = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SpecsList").getSheetValues(3, 2, 1, 3);
  Logger.log(voltCompareData);
  var voltSample1 = voltCompareData.getValue(1,1);
  Logger.log(voltSample1);
}

The variable voltSample1 was my attempt at extracting the first number from the array produced by the voltCompareData variable for comparison purposes.

Please refer to the image for the specific number and array obtained and recorded through the aforementioned script.

Answer №1

Comparing voltage data with a variable

function checkVoltage() {
  var requiredVoltage = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("A1").getValue();
  var voltageSpecs = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SpecsList").getSheetValues(3, 2, 1, 3).flat();
  voltageSpecs.forEach(spec => {
    if(spec == requiredVoltage) {
      //perform some action
    }
  });
}

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

Customizing error styles in a table using Jquery validation

My form is using JQuery .validation(). Here is the structure of my form: <form....> <table cellspacing="0" cellpadding="0"> <tr> <td>Name: </td> <td><input type='text' name='Name'/></td> ...

I have not made any changes to the <div> tag with my CSS or JavaScript coding

Click here to see the problem I am facing on JSFiddle. I am trying to create a loading screen that will slide up after a few seconds using jQuery. Although I am familiar with HTML, JavaScript, and CSS, I am still new to jQuery. I have a feeling that the so ...

Creating a structured model design in Javascript using Backbone framework

I am relatively new to JavaScript, so please bear with me as I ask this question. Currently, for my project, I am using NodeJS for the server and Backbone for the client. The idea is that the client will send a request to the server, which will then respo ...

Numpy now has the ability to automatically convert np.arrays into lists with implicit conversion

In the process of creating a `numpy.array` of other `numpy.array's` for a Monte Carlo simulation, I am encountering an issue. I am attempting to take an element of the array (which is another 1d array), perform a function on it to return a subsection ...

Express template failing to connect with scripts, css, and images

When using Express, I encounter difficulty in getting the css, js, and images to link up correctly when running the index.html file. The images are not showing up and the css and js files are not linking properly. <link rel="stylesheet" type="text/css" ...

When capturing photos using h5 on iOS devices, the browser may experience a flash back issue

I have been searching Baidu and Google for a while now, but I still haven't found a solution. Here is the specific issue: When using h5 to take photos on iOS systems, the browser flashes back. HTML Code <img src="xxx" onclick="sta ...

Sending PDF file to client's request using PDFKIT and Strapi (Koa) via HTTP response

My goal is to send a PDF file as a response to a GET request on my Strapi endpoint. The current Strapi controller, which uses Koa, is structured like this: const PDFDocument = require("pdfkit"); module.exports = { async printOne(ctx) { const doc = ...

Efficient method for generating a pairwise distance matrix among rows of a two-dimensional array in record time

Currently, I am facing an issue with the performance of my code. Using a string in np.array leads to N^2 complexity and for a matrix with 10k rows and 10 columns, it takes more than 1 hour to execute, which is unacceptably slow. However, I am at a loss on ...

Creating internal utility functions in Angular without exporting them as part of the module can be achieved by following a

Currently, I'm in the process of creating an angular module called MyModule. This module includes several sub-modules. angular.module('MyModule', [ 'MyModule.SubModule1', 'MyModule.SubModule2', 'MyModule.SubMo ...

Experiencing the swift blink of secure route's content using React Router 6

After implementing a "protected route" using React Router 6, I noticed that the protected page's content briefly flashes before redirecting to the login page. Is there a known solution to this issue? Here is the code for the ProtectedRoute component: ...

Angular HTML is throwing an error related to object arrays

Is there a way to display only specific fields of an array? <div class="form-check" *ngFor="let periodo of filterPeriodos()"> <div>{{periodo.periodos | json}}</div> <input class="form-check-input mr- ...

Create a two-dimensional array during compilation and enable user input for its values

Is there a way to define an array with the size determined at runtime or compile time using an overload constructor? private: int** arr = nullptr; void overloadConstruct(int n) { arr = new int*[n]; for (int i = 0; i < n; ++i) { arr[i] = new int[n]() ...

Prevent selection of weekend dates in Angular Bootstrap datepicker with a personalized directive

I have integrated the Angular Bootstrap datepicker plugin into my Angular application. To customize the date pickers in my app, I created a custom directive. In certain places, I need to disable weekends in the date picker. I have added the functions to d ...

The art of properly indenting coffee script code

I encountered an indentation error in these lines Are there any online validators that can assist me? showAliveTests : (pageIndex, statusFilter) -> data= pageIndex:pageIndex status:statusFilter $.ajax u ...

Switching up the content of an HTML page with JavaScript or JQuery: what you need

Is it possible to update HTML content using JavaScript or JQuery? https://i.sstatic.net/EWOXg.png I am trying to change the contents from 1 to 5 in a sequential order based on the time shown in the image. How can I achieve this using JavaScript or JQuery ...

How can you eliminate a specific element from an HTML document?

Utilizing localStorage can be tricky when it comes to keeping the JSON file hidden from being displayed on the HTML page. One approach I used involves sending the JSON file to the client once and then performing all logic using that file. To prevent the JS ...

Using i18next to alter language in a React app

Implementing the i18next translation system into my React app was a breeze thanks to a helpful guide I found. However, I'm facing an issue with changing the language manually. The guide covered the setup process perfectly, but lacked information on ho ...

Testing the Mongoose save() method by mocking it in an integration test

I am currently facing an issue while trying to create a test scenario. The problem arises with the endpoint I have for a REST-API: Post represents a Mongoose model. router.post('/addPost', (req, res) => { const post = new Post(req.body); ...

Check if a string includes any elements from an array and substitute them with a random synonym from the array

I am looking to randomly swap out words in a given text with synonyms from a predefined list. My goal is to identify if the input text contains any words from a specific array, and if so, replace them with a synonym from the same list at random. var input ...

The firebase collection's model doesn't include an add function within its nested collection

I'm currently developing an application where I aim to utilize Firebase for real-time data storage within the context of the Backbone framework. The issue I am facing is as follows: I have a sub-level model and collection, both of which are standar ...