'Fill Down values from a 1x6 array into an _x6 array Google App Script for Google Sheet
I've got this:
array_to_fill_down = [a, b, c, cat, 15, blue]
rows = 3
What I want is this: array_output
[
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue},
{a, b, c, cat, 15, blue}
]
Sorry, I know I'm probably not using the correct symbols. That's part of my problem, I'm sure.
Thanks!
Solution 1:[1]
You've asked for a script specifically. But in the event that you or a future site visitor wanted to do this with a formula:
=ArrayFormula(TRANSPOSE(SPLIT(REPT({"a";"b";"c";"cat";15;"blue"}&"~",3),"~",1,0)))
If the array to repeat were to be entered into a horizontal range (say, A1:F1):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(TRANSPOSE(A1:F1)&"~",3),"~",1,0)))
And if that to-be-filled array were entered into a vertical range (say, A1:A6):
=ArrayFormula(TRANSPOSE(SPLIT(REPT(A1:A6&"~",3),"~",1,0)))
Solution 2:[2]
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'])])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
