Home:ALL Converter>How do I splice a 2D array in Google Apps Script?

How do I splice a 2D array in Google Apps Script?

Ask Time:2022-11-17T04:46:15         Author:MeesterZee

Json Formatter

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']]

Author:MeesterZee,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74467007/how-do-i-splice-a-2d-array-in-google-apps-script
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
yy