在Google应用程序脚本(Google Apps Script)中,可以使用以下方法从数组中提取行:
function extractRowsFromArray() {
var data = [
["John", "Doe", "john@example.com"],
["Jane", "Smith", "jane@example.com"],
["Bob", "Johnson", "bob@example.com"]
];
var extractedRows = [];
for (var i = 0; i < data.length; i++) {
if (data[i][0] === "Jane") { // 根据条件筛选行
extractedRows.push(data[i]);
}
}
Logger.log(extractedRows); // 打印提取的行
}
function extractRowsFromArray() {
var data = [
["John", "Doe", "john@example.com"],
["Jane", "Smith", "jane@example.com"],
["Bob", "Johnson", "bob@example.com"]
];
var extractedRows = data.filter(function(row) {
return row[0] === "Jane"; // 根据条件筛选行
});
Logger.log(extractedRows); // 打印提取的行
}
以上代码示例中,我们假设有一个包含姓名、姓氏和电子邮件的二维数组。我们使用for循环或filter()方法遍历数组,并根据条件筛选出满足条件的行。提取的行将存储在一个新的数组中,并使用Logger.log()方法打印出来。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云