我想使用 Google Apps 脚本删除数组中的所有空格

I would like to remove all blank spaces in an array using Google Apps Script

这是我的程序片段。

function onFormSubmit() {
var fr = ss.getSheetByName('Form Responses')
var lastRowValues = fr.getRange(fr.getLastRow(), 2, 1, fr.getLastColumn()).getValues() 
Logger.log(lastRowValues)
var i = lastRowValues.length;    
while(i--) !/\S/.test(lastRowValues[i]) && lastRowValues.splice(i, 1);
Logger.log(lastRowValues)
}

Here is the output, but as you can see my code does not remove the blank elements of the array

任何帮助将不胜感激。谢谢!

这是一个二维数组。您只是在测试外部数组(长度:1),而您需要测试内部数组。

var i = lastRowValues[0].length;    
while(i--) (!/\S/.test(lastRowValues[0][i])) && lastRowValues[0].splice(i, 1);