将 1x6 数组中的值向下填充到 _x6 数组中 Google Google Sheet 的应用程序脚本
Fill Down values from a 1x6 array into an _x6 array Google App Script for Google Sheet
我知道了:
array_to_fill_down = [a, b, c, cat, 15, blue]
rows = 3
我想要的是这样的:
array_output
[
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue}
]
抱歉,我知道我可能没有使用正确的符号。我确定那是我问题的一部分。
谢谢!
大概是这样的:
array_to_fill_down = ['a', 'b', 'c', 'cat', 15, 'blue'];
rows = 3;
var new_array = [];
while (rows--) new_array.push(array_to_fill_down)
或
var new_array = new Array(rows).fill(array_to_fill_down);
不过不确定我是否理解您的目标。
console.log([...Array.from({length:3}, x => ['a', 'b', 'c', 'cat', 15, 'blue'])])
console.log([...Array.from(Array(3), x => ['a', 'b', 'c', 'cat', 15, 'blue'])])
你特意要了一个剧本。但如果您或未来的网站访问者想要使用公式来执行此操作:
=ArrayFormula(TRANSPOSE(SPLIT(REPT({"a";"b";"c";"cat";15;"blue"}&"~",3),"~",1,0)))
如果要将要重复的数组输入水平范围(例如,A1:F1):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(TRANSPOSE(A1:F1)&"~",3),"~",1,0)))
并且如果将要填充的数组输入垂直范围(例如,A1:A6):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(A1:A6&"~",3),"~",1,0)))
我知道了:
array_to_fill_down = [a, b, c, cat, 15, blue]
rows = 3
我想要的是这样的: array_output
[
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue}
]
抱歉,我知道我可能没有使用正确的符号。我确定那是我问题的一部分。
谢谢!
大概是这样的:
array_to_fill_down = ['a', 'b', 'c', 'cat', 15, 'blue'];
rows = 3;
var new_array = [];
while (rows--) new_array.push(array_to_fill_down)
或
var new_array = new Array(rows).fill(array_to_fill_down);
不过不确定我是否理解您的目标。
console.log([...Array.from({length:3}, x => ['a', 'b', 'c', 'cat', 15, 'blue'])])
console.log([...Array.from(Array(3), x => ['a', 'b', 'c', 'cat', 15, 'blue'])])
你特意要了一个剧本。但如果您或未来的网站访问者想要使用公式来执行此操作:
=ArrayFormula(TRANSPOSE(SPLIT(REPT({"a";"b";"c";"cat";15;"blue"}&"~",3),"~",1,0)))
如果要将要重复的数组输入水平范围(例如,A1:F1):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(TRANSPOSE(A1:F1)&"~",3),"~",1,0)))
并且如果将要填充的数组输入垂直范围(例如,A1:A6):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(A1:A6&"~",3),"~",1,0)))