How to unset a JavaScript variable?

后端 未结 11 2019
执笔经年
执笔经年 2020-11-22 04:16

I have a global variable in JavaScript (actually a window property, but I don\'t think it matters) which was already populated by a previous script but I don\'t

11条回答
  •  有刺的猬
    2020-11-22 05:08

    The delete operator removes a property from an object.

    delete object.property
    delete object['property']
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete

    According to the question you need one of followings

    delete some_var;
    delete window.some_var;
    delete window['some_var'];
    

提交回复
热议问题