In google app scripts, I have a one-dimensional data array that I can get values from this:
data[0]
I would like to pass the name of the column, namely:
data("A")
Thus, I do not need to convert the letters to their position in the array. Therefore, I would like to expand the array object (the extension is not risky, since it works in an isolated script environment).
I know that I can add a function to the prototype of the array using this letter for the number function and this question of expanding the object like this:
Array.prototype.byCol = function(colName) {
return this[getColumnNumber(colName) - 1];
}
function getColumnNumber(str) {
var out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out;
}
var data = [1,2,3,4];
document.write(data.byCol("B"));
Run codeHide resultBut this is a bit more complicated call syntax than I wanted.
, , , , :
var test = new func(function() {
});
, ?