0

I am currently trying to create a Scrabble Game word scorer. So far, it has been going well, but I've run into an issue. I have one main row (A2:AP2) that contains formulas and calculates the word score. I want to get the values from that entire row each time someone submits a word, and create a record of all the words someone has submitted.

The code below starts that process, but whenever i run the script, it appends "[Ljava.lang.Object;@536f3e11" instead of the actual array values.

var p1ScoreCalc = p1Sheet.getRange('A2:AP2').getValues();

//---Array for score records---\\
var array = []

//---Checks if submit is checked--\\
if(submitCheck == 1){

//---Checks for what player is submitting---\\
if(playerCheck === "P1"){

array.push(p1ScoreCalc);

testSheet.appendRow(array);

}
}

Append Row result

I cannot figure out why this is happening. This is not my first time using appendRow(), and i cannot seem to find what I am doing wrong. I could be missing something very simple.

Here is the spreadsheet link for reference: https://docs.google.com/spreadsheets/d/1pgsE_OtO8MEqoVcGH5csQ43BOm9kx5XbagwhNTpfSk4/edit?usp=sharing

kaitlynmm569
  • 1,605
  • 1
  • 6
  • 18
  • 1
    Use [flat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) – TheMaster Jul 30 '20 at 15:13

2 Answers2

0

appendRow requires an Array of numbers, strings, booleans and/or Date objects but your code is sending an Array of Arrays. The inner Array is also an Array of Arrays.

Instead of push you might need to use concat. See How to extend an existing JavaScript array with another array, without creating a new array.

Reference

Rubén
  • 34,714
  • 9
  • 70
  • 166
0
if(submitCheck==1 && playerCheck=="P1"){
  testSheet.appendRow(p1Sheet.getRange('A2:AP2').getValues()[0]);//append a flattened array
}
Cooper
  • 59,616
  • 6
  • 23
  • 54