I have a code that is half working, the last thing I can't figure out is how to find an array item containing a number (eg 123) and some text (m/s) and replace this whole item with a completely blank array item: []
. No number and no m/s.
I am not familiar with most of the terminology and am a complete novice at this. This is what I've got so far:
function condForm() {
var sh = ss.getSheetByName('Sheet1');
var range = sh.getRange("D4:D20"); //*** for the sake of brevity setting to 20 instead of 154
var values = range.getValues();
var row = [];
var cols = values[0].length;
for (var i = 0, l = values.length; i < l; i++)
{
row = values[i];
for (var j = 0; j < cols; j++)
{
if (row[j] === 'TTK') { row[j] = ''; }
if(typeof row[j] != "string") { continue; } // line to allow indexOf to work
if (row[j].indexOf('m/s') > -1) { var newValue = row[j].replace('m/s', '') } //attempting to use indexOf to search for partial match to m/s, does not work but does not return error
}
}
Logger.log(values);
}
Without code the logger outputs [[400.0], [600.0], [600.0], [600.0], [], [1283 m/s], [TTK], [440.0], [661.0], [771.0], [771.0], [], [960m/s], [TTK], [381.0], [667.0], [667.0]]
And with the code above the output becomes [[400.0], [600.0], [600.0], [600.0], [], [1283m/s], [], [440.0], [661.0], [771.0], [771.0], [], [960m/s], [], [381.0], [667.0], [667.0]]
= same number of array items = great success
I attempted to use indexOf to search for any array items containing m/s. It didn't work but also didn't return an error. What's it doing? Am I on the right lines at all?
I would like a way to turn [1283m/s]
and [960m/s]
into blanks: []
.
Thank you for reading.
My code was sourced from Max Makhrov: https://stackoverflow.com/a/47575871/1341041
and from Andres Duarte: https://stackoverflow.com/a/60226151/1341041