Make any JavaScript method available in Google Sheets
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
Original Link: https://dev.to/all_stacks_developer/make-any-javascript-method-available-in-google-sheets-16ad
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To