Search code examples
javascriptgoogle-sheets-macros

Single string to array JavaScript


I have selected a range from google sheet. When I select a column it usually becomes array. but when I selected a row it became single string.

How do I solve this? Mentioned below is my code:-

dMatch = sheet.getRange("A2:CE2").getValues();

This coverts the row into a single string array which I don't want.

I tried split method but it throws some error.

dMatch = dMatch.split(",");

Solution

    1. Object to String.
    2. Split comma(,)
    dMatch = sheet.getRange("A2:CE2").getValues();
    dMatch = JSON.stringify(dMatch).split(",");