我正在尝试在google doc中打印出数组的值。我得到了正确的值,但它继续打印出一些“未定义”的值。最简单的方法可能是在打印出数组之前过滤掉未定义的值。
这是数组声明:
var paramArr = Object.keys(e.parameter).reverse();
var tableArr = [];
for(var i = 0; i < paramArr.length - 1; i++) {
var tempArr;
var nameSelector = "Company:" + i;
var startDateSelector = "Started:" + i;
var endDateSelector = "Ended:" + i;
var referenceSelector = "Reference:" + i;
var descriptionSelector = "Description:" + i;
tempArr = [e.parameter[nameSelector] + " ",
e.parameter[startDateSelector] + " - " +
e.parameter[endDateSelector]+ "\n\n" +
e.parameter[descriptionSelector]
];
我试过这个,但它不起作用:
tempArr = tempArr.filter(function(element){
return element !== undefined;
});