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…


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.

Slice array in Google Sheets

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Make any JavaScript method available in Google Sheets." All Stacks Developer | Sciencx - Friday September 30, 2022, https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/
HARVARD
All Stacks Developer | Sciencx Friday September 30, 2022 » Make any JavaScript method available in Google Sheets., viewed ,<https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/>
VANCOUVER
All Stacks Developer | Sciencx - » Make any JavaScript method available in Google Sheets. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/
CHICAGO
" » Make any JavaScript method available in Google Sheets." All Stacks Developer | Sciencx - Accessed . https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/
IEEE
" » Make any JavaScript method available in Google Sheets." All Stacks Developer | Sciencx [Online]. Available: https://www.scien.cx/2022/09/30/make-any-javascript-method-available-in-google-sheets/. [Accessed: ]
rf:citation
» Make any JavaScript method available in Google Sheets | All Stacks Developer | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.