6

Currently working with arrays of objects of arrays of objects and filtering those lists to generate new lists, but do not want to mutate the original list.

To do this, I clone the data, and in plain javascript I easily accomplish this with structedClone(). See JS fiddle: https://jsfiddle.net/vhekqx2a/

 const items = [
     {"name": "one", list: [{'name': 'listItemOne'}]},
     {"name": "two", list: [{'name': 'listItemOne'}]},
 ];
  
 //DEEP CLONE
 const itemsDeepClone = structuredClone(items);

MDN: https://developer.mozilla.org/en-US/docs/Web/API/structuredClone

However, when I attempt to use this in an LWC, I get the following error:

[structuredClone is not a function]

Can someone explain what it is about LWC that makes this function not available? Is it due to lightning locker service?

1 Answer 1

8

for future reference, you can verify what api's are supported using the
Locker API Viewer

enter image description here

as you can see, this is not supported yet.

2
  • is there any workaround? how can we call browser structuredClone function?
    – Patlatus
    Feb 20, 2023 at 11:35
  • 1
    if you need to deepclone you can workaround with JSON.parse(JSON.stringify(object)); Mar 7, 2023 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .