splice seems to be creating a dynamic relationship between spliced in elements and the elements they were spliced from ... ???
Say I have an array Array = [ [1 , 2 , 3] ]
I want to duplicate this column and change the last value of the new column to 4. I used: nada = Array.splice(0,0,Array[0]); Array[1][2] = 4;
However, this results in Array = [ [ 1 , 2 , 4] , [ 1 , 2 , 4] ]
This is a stripped down example, in the actual problem I'm iterating through solutions adding possibilities at each step, so nested loops would get messy ...
Insights?? .. or: how do I duplicate a column in the middle of an array and change one of it's values?
I believe your goal is as follows.
[[1, 2, 3]]to[[1, 2, 3, 4]]usig Google Apps Script.Modification points:
Arrayis an object. In this case, I would like to recommend renaming the variableArray.array.splice(0, 0, array[0]),[1, 2, 3]is inserted to the top element.array[1][2] = 4,3of[1, 2, 3]is replaced with4. Also, in this case, both elements are changed with the pass-by-reference. By this, the result is[ [ 1 , 2 , 4] , [ 1 , 2 , 4] ].When these points are reflected in the script, how about the following modifications?
Modified scripts:
[ [ 1, 2, 3, 4 ] ]from[[1, 2, 3]].Note:
[[1, 2, 3]]to[[1, 2, 4]]usig Google Apps Script, how about the following samples?References:
Added:
From your following reply,
I understood that you wanted to achieve
[[1, 2, 3]]to[ [ 1,2,3],[1,2,4]]. In this case, how about the following sample script?