Unexpected token error for arrays

25 views
Skip to first unread message

Ankita Acharya

unread,
Feb 27, 2025, 12:15:14 PM2/27/25
to LIONESS Lab help and discussion
Hi, 

I am repeatedly encountering this error message in the console of an unexpected token when I attempt to use getValue() to recover an array. This error comes up whether or not I am using a JSON array or not. I am able to use getValue() to see the array on the page that the array is originally defined, but not able to recover it later. Please let me know how best to work through this error!

Error message: 

VM239:1
Uncaught SyntaxError: Unexpected token '<', "<br /> <b>"... is not valid JSON at JSON.parse (<anonymous>) at getValue (jsLibrary.js?v8.4:418:17) at stage438951.php?sess7110da799da3:105:23


getValue

@

jsLibrary.js?v8.4:418


(anonymous)

@

stage438951.php?sessf327110da799da3:105

My code:

Page 1:
// Create array for proposerHistory
let proposerRecord = [];
setValue("proposerHistory", proposerRecord);
console.log("Proposer history:", proposerRecord);
- This works fine and returns an empty array

Page 2:
let proposerHistory = getValue('proposerRecord');
console.log(proposerRecord);
- getValue() results in this error. 

Thank you for the help. 

Best,
Ankita

in...@lioness-lab.org

unread,
Feb 27, 2025, 2:47:25 PM2/27/25
to Ankita Acharya, LIONESS Lab help and discussion

Hi Ankita,

 

Arrays need to be processed by JS before they can be recorded in the database. One simple way is to first save the array as a comma separated string (using the JS “join” function).  When you retrieve that in a later stage, you can do this with getValue and then parse it into an array again (using the JS “split” function).

 

Hope this helps!

 

Lucas

--
You received this message because you are subscribed to the Google Groups "LIONESS Lab help and discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lioness-lab...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/lioness-lab/09e5585f-167f-4e15-83e3-922584c1a904n%40googlegroups.com.

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages