smart-mobile-studio

How to remove a property from JS object


How can I remove a property from a variant object in Smart Pascal?

In JavaScript I can remove a property with the delete keyword delete obj['myProp'].

How to do it in Smart Pascal?


Solution

  • Smart allows you to directly execute JavaScript code by reusing Delphi's asm syntax.

    asm
      delete @obj['myProp'];
    end;
    

    The @obj syntax is necessary if you are referring to a Smart Pascal entity because the actual name may be something else than obj due to obfuscation. During compilation, @obj is replaced with the actual name of the entity.