This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by All Stacks Developer
Many functions in Google Sheets return an array as the result. However, I find that there is a lack of built-in support functions in Google Sheets when working with an array.
In JavaScript, there is the SLICE method that can return a part of an array. If I have an array const pricesWithHeader = ['Close', 10.5, 10.3, 10.1, 10.0];
, to get only the last 4 elements [10.5, 10.3, 10.1, 10.0]
, I can apply the SLICE method like const pricesWithoutHeader = pricesWithHeader.slice(1)
;. How to slice an array in Google Sheets?
Google Sheets has scripting capability with Apps Script based on JavaScript. So to slice an array in Google Sheets, I need to create a SLICE method in Apps Script that wraps the original SLICE method of JavaScript. By doing so, the SLICE function is available to use in every cell of a spreadsheet.
The source code and the demo can be found in the blog post
https://www.allstacksdeveloper.com/2022/09/slice-array-in-google-sheets.html
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by All Stacks Developer

All Stacks Developer | Sciencx (2022-09-30T20:15:42+00:00) Make any JavaScript method available in Google Sheets. Retrieved from https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.