【发布时间】:2018-11-07 09:20:50
【问题描述】:
输入一个二维数组,我需要得到一个包含大写元素的数组作为输出。
这是我的尝试,但它不起作用。
var cityColumn = [['avila'], ['burgos'], ['madrid'], ['sevilla']];
var cityRow = [['avila', 'avila', 'burgos', 'madrid', 'sevilla']];
var cityCell = [['sevilla']];
console.log(cityRow);
function upperCaseArray(myArray) {
var upperized = myArray.map(function(city){
console.log(typeof city);
return city.toUpperCase();
});
return upperized;
}
console.log(upperCaseArray(cityColumn));
console.log(upperCaseArray(cityRow));
console.log(upperCaseArray(cityCell));
// output desired:
// [['AVILA], ['BURGOS'], ['MADRID'], ['SEVILLA']]
// [['AVILA, 'AVILA', 'BURGOS', 'MADRID', SEVILLA']]
// [['SEVILLA']]
注意:这些输入是我从 Google 表格范围 SpreadsheetApp.getActiveSpreadsheet().getSelection().getActiveRange().getValues() 获得的。我正在开始编写 Google Apps 脚本。
【问题讨论】:
标签: javascript arrays string google-apps-script map-function