How do I clear settings from the Drupal object? I have a module, which renders an AJAX form, which passes data to a script via drupal_add_js and stores it in the settings property of the Drupal object. My problem is that I cannot seem to remove old data from the object (a user can toggle options on the form and send new datasets to the javascript). Logically, I thought passing an empty array would clear the values, but it doesn't.

// Clear old data from settings.
$js = array(
  'd3' =&gt; array(
    'inventory' =&gt; array(
      'chart' =&gt; array(
        'dataset' =&gt; array(),
      ),
    ),
  ),
);
drupal_add_js($js, 'setting');


I need something like drupal_remove_js($js, 'setting')? or a method for removing object properties?
drupal_add_js adds javascript to the page &lt;head&gt;, so as far as I know you can't change that anymore with AJAX. Thus placing it in an AJAX callback doesn't work. You need to solve this at Javascript level in the the browser.

You'll have to make sure all data for all options is sent to the client during rendering and then use simple jQuery selectors to enter the correct part of data into the visualizer.