structuredClone shows not defined

structuredClone() has been around for a bit now but it still shows undefined in the editor. Is this a something the retool team can fix.
image

Also what is best practice?:
if i have a variable in my app that holds data. And i have a js query that references that variable and i then modify it for to then upload in a different variable should i be making a copy of it with structuredClone() or JSON.parse(JSON.stringify()).

image

Hey @PadenM!

  1. Filed this as a bug :bug:
  2. For best practice, it depends.
  • JSON.parse(JSON.stringify()) works well for plain data types (objects and arrays containing only JSON-serializable data types: string, number, object, array, true, false, null), but does not work well with objects containing functions, Date objects, or non-JSON-serializable values.
  • structuredClone() preserves functions, Date objects, and other non-JSON-serializable values as it's designed for cloning structured data, including more complex objects. With that said, there may be limited browser support for this method.
  • _.cloneDeep() could also be a good option for you! Retool has Lodash built in, so you can try it out if you'd like :slight_smile: https://lodash.com/docs/4.17.15#cloneDeep

Let me know if you have any other questions!