0

I'm new to JS and developing in general and I'm kind of stuck here.

I want to use a google Sheet as a backend and query it with js/jquery. I queried the sheet correctly and parsed every row of it (achieved with a forEach). The results from column D and B are combined to a string in the end. I got this working, but, of course, I have 5 outputs or so.

So at the moment, every row (5 rows in the sheet) is a single output, concatenated to a string, so the final output is: output(d[i])+string+output(b[j]) , where i and j are the variables from the for loops.

The result in the console is:

(index):103 AccessRequestPending
(index):103 AccesssDenied
(index):103 NotConfirmed
(index):103 toOldVersion
(index):103 UnknownReason

These are the results, when I run the script (only for column D). I can't push the results to an array, because it pushes the result 5 times to the same array. So in the end, there's just one array with [UnknownReason], But I need 1 array(or just the strings, it doesn't matter) with the 5 results concatenated.

I'd like to achieve something like

output(d[i1])+string+output(b[j1]) + output(d[i2])+string+output(b[j2]) + output(d[i3])+string+output(b[j3])

So, I really want to figure it out by myself, but can you tell me how to use every output/result of an iteration and concat it with the iteration before? Or maybe extract each result to it's own variable?

Thanks in advance!

1
  • 3
    it might help to share a code snippet that currently gives you the results you are seeing. Commented Feb 28, 2018 at 18:53

2 Answers 2

1

I understand that you want to sum all those cells and get the total, if that is your question, you can use JavaScript reduce to concatenate your array in a single result.

Another options can be:

Let me know if this solve your question.

Best

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

Comments

0

Sorry, I wasn't available. I combined these 2 arrays into one to map with each other.

let arrayCombined2 = reasonsArray.reduce(function(arr, v, i) {
     return arr.concat(v, arrayUrls[i])}

or for jquery:

let arrayCombined = $.map(reasonsArray, function(k, i) {
return [k, arrayUrls[i]]; 

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.