How do I "unset" SKU from an item in JavaScript?

I have tried:

l.sku = undefined;
// this writes “undefined” into SKU field

l.sku = ‘’;
// this writes empty string to SKU

delete l.sku;
// this does nothing

How can I make l.sku undefined again so typeof l.sku == ‘undefined’ is true?
Please advise, thanks! --vlad.

Have you tried the following???

listing.sku = “”;
listing.useSKU = false;

Neal

Yes, see above. This sets sku as “”, not as undefined value in javascript.

Would listing.sku.isEmpty() work in the context you’re developing? You could combine it with an undefined check if you’re worried about that.

Javascript specifically uses undefined for variables that have never been set. There is no way to make an existing variable undefined AFAIK.

Not tested, but have you tried:

l.sku = null;

Not sure how Apple’s JavaScript interpreter handles this.

Yes, I can check if (typeof listing.sku == ‘undefined’ | listing.sku == ‘’) and it solves the issue. I thought you can actually set a variable as undefined specifically by assigning it to undefined value, or use delete to remove a property. Not an expert in javascript though, RTFM as I go :). Thanks!

This assigns sku as ‘null’ string :).

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.