I have encountered an issue with two arrays of values. I am trying to utilize the elements from one array as arguments for an indexOf
function, but I consistently receive a -1
(indicating that the value is not found) even though I know the value exists in the array.
To troubleshoot, I manually input the value into the argument of indexOf
, which confirmed that the problem lies within the cur_data
variable. When I substituted cur_data[x]
with 'xyz'
, the indexOf
function returned the correct index. However, when using the actual array value [xyz]
, it resulted in -1
.
Can you help me identify what mistake I am making?
function iterateSheets() {
var price_data = SpreadsheetApp.openById('1Nttb7XqUlZwGtmwbcRc3QkY3f2rxx7XdsdEU3cK4K4').getSheetByName('price').getRange("A2:A353").getValues()
var price_data2 = price_data.map(function(r) {
return r[0];
});
var test = new Array(30)
var ts = SpreadsheetApp.openById('18qFvVMVEE1k5DWUYaSezKeobcLr8I4oAmHLUpd_X99k');
var allShts = ts.getSheets();
for (var i = 0; i < 1; i++) //allShts.length //need to add in code to make sure tab is one of the fcst tabs
{
var cur_data = allShts[i].getRange("B8").getValues()
if (allShts[i].getName() == "July" || allShts[i].getName() ==
"Aug" || allShts[i].getName() == "Sept") {
for (var x = 0; x < 1; x++) {
Logger.log(cur_data[x])
Logger.log(price_data2.indexOf(cur_data[x]));
}
}
}
}