如何单独获取行的每个值并将它们放入数组
How to get row's every value individually and put them to array
我是google脚本的新手,请帮助我理解。
例如,我的行是 [11, 22, 33, 44]
我想单独得到它们
11
22
33
44
并可能将它们中的每一个添加 +1 或 +5 并像这样将它们放入数组中
`
[[11], [22], [33], [44]]
或者如果 +1
[[12], [23], [34], [45]]
`
我怎样才能做到这一点以及我可以使用什么类型的方法或功能
请举例说明
说明
这里很好参考,学习javascript Javascript Tutorial Using Array.map(),对数组的每个元素执行一个函数
脚本
function unFlat() {
try {
let a = [11,22,33,44];
let b = a.map( x => [x] );
let c = 5;
let d = a.map( x => [x+c])
console.log(a);
console.log(b);
console.log(d);
}
catch(err) {
console.log(err);
}
}
6:10:04 AM Notice Execution started
6:10:04 AM Info [ 11, 22, 33, 44 ]
6:10:04 AM Info [ [ 11 ], [ 22 ], [ 33 ], [ 44 ] ]
6:10:04 AM Info [ [ 16 ], [ 27 ], [ 38 ], [ 49 ] ]
6:10:04 AM Notice Execution completed
参考
将所有行放入列中
function putallrowsintocolums() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet0');
const vs = sh.getDataRange().getDisplayValues();
let nr = sh.getLastRow() + 1;
vs.forEach((r,i) => {
sh.getRange(nr,i+1,r.length).setValues(r.map(e => [e]));
});
}
我是google脚本的新手,请帮助我理解。 例如,我的行是 [11, 22, 33, 44] 我想单独得到它们 11 22 33 44 并可能将它们中的每一个添加 +1 或 +5 并像这样将它们放入数组中 `
[[11], [22], [33], [44]]
或者如果 +1
[[12], [23], [34], [45]]
` 我怎样才能做到这一点以及我可以使用什么类型的方法或功能 请举例说明
说明
这里很好参考,学习javascript Javascript Tutorial Using Array.map(),对数组的每个元素执行一个函数
脚本
function unFlat() {
try {
let a = [11,22,33,44];
let b = a.map( x => [x] );
let c = 5;
let d = a.map( x => [x+c])
console.log(a);
console.log(b);
console.log(d);
}
catch(err) {
console.log(err);
}
}
6:10:04 AM Notice Execution started
6:10:04 AM Info [ 11, 22, 33, 44 ]
6:10:04 AM Info [ [ 11 ], [ 22 ], [ 33 ], [ 44 ] ]
6:10:04 AM Info [ [ 16 ], [ 27 ], [ 38 ], [ 49 ] ]
6:10:04 AM Notice Execution completed
参考
将所有行放入列中
function putallrowsintocolums() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet0');
const vs = sh.getDataRange().getDisplayValues();
let nr = sh.getLastRow() + 1;
vs.forEach((r,i) => {
sh.getRange(nr,i+1,r.length).setValues(r.map(e => [e]));
});
}