I am trying to splice a 2D array in Google Apps Script. I have the following code, but it only works with a 1D array:
function trimArray() {
var myArray = ['1', '2', '3', '4', '5', '6,', '7', '8', '9', '10'];
myArray.splice(3, myArray.length);
console.log(myArray);
}
How do I modify the code above to work with this array?
[['1', '2', '3', '4', '5', '6,', '7', '8', '9', '10']]
The output should be the same as the function above, but still maintain a 2D array:
[['1', '2', '3']]
TheWizEd :
Try this one\nfunction test() {\n try {\n let a = [['1', '2', '3', '4', '5', '6,', '7', '8', '9', '10']];\n a[0] = a[0].slice(0,3);\n console.log(a)\n }\n catch(err) {\n console.log("Error in test: "+err);\n }\n}\n\n2:59:19 PM Notice Execution started\n2:59:20 PM Info [ [ '1', '2', '3' ] ]\n2:59:20 PM Notice Execution completed\n",
2022-11-16T23:00:58