-1

I'm using getDataRange().getValues() to copy data from a Google sheet to an array which I can work with.

i thought I had been successful and have been workng with several datasets in this manner until now, however I attempted to use filter() on the array without success. Stack Overflow informed me that the array is not valid (it's just a Javascript object, but not an array).

The format is like this:

[
  [a1,a2,a3,a4],
  [b1,b2,b3,b4],
  [c1,c2.c3,c4]
]

Note the missing apostrophes around each value.

This is the code I'm using to create the object:

var allTrans = sheet.getDataRange().getValues();

What am I doing wrong? Is there away to get the sheet values into a valid array or does anyone have any suggestion on the best way to wrap each value into quotes, so I can use filter on it?

This is related to a question I asked earlier here.

Ideally, I'd like the structure of resulting array to the same as above, since I've already written nearly 1,000 lines of code accessing the array using alltrans[i][0] (etc.). Thanks,

4
  • Can you share a sample spreadsheet with some data? Or are you mutilating/ altering the array in some other part of your script? Commented Apr 16, 2018 at 14:41
  • I'm only accessing the array in other parts of my scripts, not altering it. It's nearly 11pm here and need to sleep but I'll look at creating something I can share in the morning if needed. Thanks. Commented Apr 16, 2018 at 14:50
  • 1
    Nothing wrong with the array. Just because you can't see the quotes doesn't mean it's not there. You're probably doing the filter wrong. Commented Apr 16, 2018 at 15:00
  • 1
    Range#getValues() is 100% returning you a valid Javascript array of Javascript arrays. If you are previewing the structure with Logger.log, stop, and use the Stackdriver console.log (then View -> Stackdriver Logs). Commented Apr 16, 2018 at 16:04

1 Answer 1

0

It comes down to the syntax of how you apply your array. Someone else explained it well in this post: How to filter an array of arrays (Google app script)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.