I've been working on a Google Sheets extension where the script analyzes data in a table structured like this: "A" | "B" | "C" | "E~F"
My goal is to split the strings in column four by the "~" symbol and create two arrays for each row. The final array should have one value from columns A, B, C, and either E or F. Here's what I'm trying to achieve: [["A","B","C","E"],["A","B","C","F"]] While this seems simple in theory, I'm running into an issue where appending my arrays ends up duplicating the second element like this: [["A","B","C","F"],["A","B","C","F"]]. It's important to note that column E may have varying numbers of elements in the future. Any guidance would be greatly appreciated!
var rangeArr=[["BF-A", "true", 'A kind reminder to make a weather report if you are on duty today', 'Something','2.0', 'Humphrey Bogart~James Dean'], ['BF-B', 'true', 'Kindly report on the condition of the BF now', 'Something else', '4.0', 'Humphrey Bogart~James Dean'], ['R-A6', 'true','A kind reminder to report on the reservoir level', 'Something completely different', '1.0', 'Angela Merkel']];
var newArr=[[]];
var count=0;
for(i in rangeArr){
var str=rangeArr[i][5];
var places=str.split("~");
var otherThings=rangeArr[i].slice();
otherThings.pop()
for (a in places){
otherThings[5]=places[a]
var nextThing=otherThings.slice();
newArr[count]=nextThing;
count=count+1;
}
}
alert(newArr)