DEV Community

All Stacks Developer
All Stacks Developer

Posted on • Updated on

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.

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


Use SPARKLINE column chart to create price chart with reference price

I own and follow several stocks in my investment portfolio. I pick a reference price for each stock. To effectively track the movement of a stock, I need to visualize its 52-week prices based on the reference price that I determined. In this post, I explain how to do so with the SPARKLINE column chart in Google Sheets.

https://www.allstacksdeveloper.com/2022/10/sparkline-column-chart-google-finance.html

Use SPARKLINE column chart to show stock price trend in Google Sheets

Oldest comments (0)