Turning single values and arrays into arrays including zeros as single value

Advertisements While I was searching for a good way to check if a function variable is an array or a single variable and then turn both into arrays for further processing, I came across this post. The answer provided by @VoteyDisciple var eventsArray = events ? [].concat(events) : []; works great for me until events… Read More Turning single values and arrays into arrays including zeros as single value

How can I map the object key and value in option HTML tags in appscript

Advertisements I am retrieving this below object from a function in Code. gs. I would like to pass the key-value pair into my HTML drop-down button. How can I map the object key and value in option HTML tags? HTML <div class="form-group"> <? var data = listAccounts() ?> <optgroup label="Ad Accounts"> <? for (i=0; i<data.length;… Read More How can I map the object key and value in option HTML tags in appscript

Cannot read properties of undefined while populating API results in drop down

Advertisements I am trying to pull GA4 Accounts from listAccounts() function and want to populate the drop-down field with GA4 List accounts on the HTML front-end. When I try to click on the custom menu in google sheets, I get this error – TypeError: Cannot read properties of undefined (reading ‘length’) HTML <div class="form-group"> <?… Read More Cannot read properties of undefined while populating API results in drop down

Removing data from API response in Apps Script using map() before printing to Google Sheets

Advertisements The code: function BTC_1hour() { var url = ‘https://openapi-sandbox.kucoin.com/api/v1/market/candles?type=1hour&symbol=BTC-USDT&startAt=1566703297&#8217;; var response = UrlFetchApp.fetch(url); // store API fetch in variable named response var JSONresponse = JSON.parse(response); var formatData = JSONresponse.data.map(([a, …v]) => [new Date(Number(a) * 1000), …v]) var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(‘1h’); sheet.getRange(4,1,formatData.length, formatData[0].length).setValues(formatData); } The response: {"code":"200000","data":[["1670414400","16805.8","16858.5","16858.5","16736.5","0.1021428","1716.165507409"],["1670410800","8000","8000","8000","8000","0.14","1120"],["1670407200","16827.9","12922.8","16827.9","12922.8","0.11241178","1848.427525934"],["1670403600","16805.1","16867.2","16889","16730","0.224152","3763.9561529"],["1670400000","16809","16830.3","25790.340298","16751.9","0.15817498","2685.85805974755522"],["1670396400","16822","16822","16822","16822","0.00118891","19.99984402"],["1670392800","16988.5","16988.5","16988.5","16988.5","0.00008","1.35908"],["1670389200","16966.4","16966.4","16966.4","16966.4","0","0"],["1670385600","16966.4","16966.4","16966.4","16966.4","0","0"],["1670382000","16966.4","16966.4","16966.4","16966.4","0.0253421","429.96420544"],["1670378400","17021","17021","17021","17021","0","0"],["1670374800","17021","17021","17021","17021","0.0000117","0.1991457"],["1670371200","17036.8","17077.6","17077.6","17036.8","0.00665796","113.430810288"],["1670367600","16986","16986","16986","16986","0.00100275","17.0327115"],["1670364000","16950.3","16936.2","16950.3","16936.2","0.0147845","250.4433039"],["1670360400","16944.6","16940.1","16944.6","16940.1","0.00910371","154.233732771"],["1670356800","16988.1","16927","17016.4","16000","0.22622738","3833.810489916"],["1670353200","16989.9","16915.4","16989.9","16915.4","0.007","118.66855"]]} formatData is using an… Read More Removing data from API response in Apps Script using map() before printing to Google Sheets

Loop breaks over an array when a condition is met with google apps script

Advertisements I have an array and I am trying to identify a particular text in every element and remove only if that element from the array where there is a match. the array is var Concat_names = [‘Prod 1-Volume based deal-100 sections’,’Test Prod 1-Included Members-MB,’Prod 2-Commitment + Excess-100 sections’,’Prod 1-Flat Mon-TB’]; If any element in… Read More Loop breaks over an array when a condition is met with google apps script

How can I search an object for certain object properties case insensitively?

Advertisements I receive an object from the Gmail API and I need to extract certain properties. The problem is that sometimes the object property I am looking for in the original object is written in capital letters and sometimes not (e.g. Content-Id instead of Content-ID). var ob = headers.find(({ name }) => name == "Content-ID");… Read More How can I search an object for certain object properties case insensitively?

How to generate uniques after subtracting arrays' elements based on conditions using JS?

Advertisements How to check if the item in array1 exists in array2 and, if so, subtract col4 from col5 to output th pending qty. If not, then, item’s qty from array1 is the pending qty. let array1 = [ [1, "Item A", "Food", 10, 0], [2, "Item B", "Food", 5, 0], [3, "Item C", "Food",… Read More How to generate uniques after subtracting arrays' elements based on conditions using JS?