title: Remove an object's key and value using a variable from function
body: <p>Hey I'm trying to remove a key:value pair from state inside a Javascript Object.</p>
  
  <p>It works when I hardcode the key name in the code, but when I try to use a variable from a function call, it does nothing.</p>
  
  <p>Can somebody help me out?</p>
  
  <p>Here's an object example:</p>
  
  <pre><code>  toppingsSelected: {
       "Onion":"true",
       "Mushrooms":"true",
    }
  </code></pre>
  
  <p>This works, hardcoded:</p>
  
  <pre><code>deleteTopping = toppingName =&gt; {
  
     const { Onion, ...withoutOnion } = toppingsSelected;
     console.log(withoutOnion); // Returns object without onion
  
    };
  </code></pre>
  
  <p>This doesn't work:</p>
  
  <pre><code>deleteTopping = toppingName =&gt; {
  
  
     const toppingName = "Onion"; // Variable gets passed in
  
     const { toppingName, ...withoutOnion } = toppingsSelected;
     console.log(withoutOnion); // Returns original object, no change made
  
    };
  </code></pre>
  
  <p>So I'm basically trying to remove a key from React state but I'm pretty new to Javascript.</p>
  
  <p>How can I make Javascript aware that toppingName is a key?</p>